Basalt icon indicating copy to clipboard operation
Basalt copied to clipboard

bug: atempt to perform arithmetic on a table value

Open mentalrob opened this issue 2 months ago • 2 comments

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!

mentalrob avatar Apr 18 '24 19:04 mentalrob

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.

zambony avatar Apr 20 '24 07:04 zambony

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 😄 .

mentalrob avatar Apr 20 '24 07:04 mentalrob