bug: atempt to perform arithmetic on a table value #109

Closed
opened 2024-04-19 03:17:22 +08:00 by mentalrob · 2 comments
mentalrob commented 2024-04-19 03:17:22 +08:00 (Migrated from github.com)

Describe the bug

I'm trying to run a code snippet shared in https://basalt.madefor.cc/#/objects/Frame

local basalt = require("basalt") -- we need basalt here

local main = basalt.createFrame():setTheme({FrameBG = colors.lightGray, FrameFG = colors.black}) -- we change the default bg and fg color for frames

local sub = { -- here we create a table where we gonna add some frames
    main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"), -- obviously the first one should be shown on program start
    main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"):hide(),
    main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"):hide(),
}

local function openSubFrame(id) -- we create a function which switches the frame for us
    if(sub[id]~=nil)then
        for k,v in pairs(sub)do
            v:hide()
        end
        sub[id]:show()
    end
end

local menubar = main:addMenubar():setScrollable() -- we create a menubar in our main frame.
    :setSize("{parent.w}")
    :onChange(function(self, val)
        openSubFrame(self:getItemIndex()) -- here we open the sub frame based on the table index
    end)
    :addItem("Example 1")
    :addItem("Example 2")
    :addItem("Example 3")

-- Now we can change our sub frames, if you want to access a sub frame just use sub[subid], some examples:
sub[1]:addButton():setPosition(2, 2)

sub[2]:addLabel():setText("Hello World!"):setPosition(2, 2)

sub[3]:addLabel():setText("Now we're on example 3!"):setPosition(2, 2)
sub[3]:addButton():setText("No functionality"):setPosition(2, 4):setSize(18, 3)

basalt.autoUpdate()

But it throws an error dynamicValues.lua:51: attempt to preform arithmetic on a table value

To Reproduce

Steps to reproduce the behavior:

  1. Clone the repository move Basalt as basalt
  2. Create a file called test.lua in computer
  3. Paste the given code
  4. Run the code and get the error

Expected behavior

Example code should work

Screenshots

image

Additional context

Checklist

[X] I am running the latest version.
Tick the box if you are running the latest version!

**Describe the bug** I'm trying to run a code snippet shared in https://basalt.madefor.cc/#/objects/Frame ```lua local basalt = require("basalt") -- we need basalt here local main = basalt.createFrame():setTheme({FrameBG = colors.lightGray, FrameFG = colors.black}) -- we change the default bg and fg color for frames local sub = { -- here we create a table where we gonna add some frames main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"), -- obviously the first one should be shown on program start main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"):hide(), main:addFrame():setPosition(1, 2):setSize("{parent.w}", "{parent.h - 1}"):hide(), } local function openSubFrame(id) -- we create a function which switches the frame for us if(sub[id]~=nil)then for k,v in pairs(sub)do v:hide() end sub[id]:show() end end local menubar = main:addMenubar():setScrollable() -- we create a menubar in our main frame. :setSize("{parent.w}") :onChange(function(self, val) openSubFrame(self:getItemIndex()) -- here we open the sub frame based on the table index end) :addItem("Example 1") :addItem("Example 2") :addItem("Example 3") -- Now we can change our sub frames, if you want to access a sub frame just use sub[subid], some examples: sub[1]:addButton():setPosition(2, 2) sub[2]:addLabel():setText("Hello World!"):setPosition(2, 2) sub[3]:addLabel():setText("Now we're on example 3!"):setPosition(2, 2) sub[3]:addButton():setText("No functionality"):setPosition(2, 4):setSize(18, 3) basalt.autoUpdate() ``` But it throws an error `dynamicValues.lua:51: attempt to preform arithmetic on a table value` **To Reproduce** Steps to reproduce the behavior: 1. Clone the repository move `Basalt` as `basalt` 2. Create a file called test.lua in computer 3. Paste the given code 4. Run the code and get the error **Expected behavior** Example code should work **Screenshots** ![image](https://github.com/Pyroxenium/Basalt/assets/31934174/87ea405f-cacd-45ba-9be8-dacb1f3721c6) **Additional context** **Checklist** [X] I am running the latest version. Tick the box if you are running the latest version!
zambony commented 2024-04-20 15:27:43 +08:00 (Migrated from github.com)

I think it's a typo on the wiki, or something changed from older versions. The dynamic values like parent.w in the code should not be surrounded in braces {}. Remove all the braces around the dynamic values you're using.

I think it's a typo on the wiki, or something changed from older versions. The dynamic values like `parent.w` in the code should not be surrounded in braces `{}`. Remove all the braces around the dynamic values you're using.
mentalrob commented 2024-04-20 15:44:41 +08:00 (Migrated from github.com)

Yeah you are right, it was a typo in the wiki. But it caused a lot of trouble to me, i spent around 3 hours to figure out whats wrong 😄 .

Yeah you are right, it was a typo in the wiki. But it caused a lot of trouble to me, i spent around 3 hours to figure out whats wrong 😄 .
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: GitHub/Basalt#109
No description provided.