Tabletop Simulator

Tabletop Simulator

View Stats:
Metalsech Jan 21, 2021 @ 9:34am
Attempt To Index A Nil Value Error On Button Creation
Hi all, I'm new to scripting in Tabletop Simulator. I'm trying to follow basic guides on coding and all of them inform me to code in global. So following directions I create a checker object which I want to attach a Setup button to. I'm running the following LUA global code:

setupguid = getObjectFromGUID('fd4710')

button_parameters = {}
button_parameters. click_function = 'setupgame'
button_parameters. function_owner = nil
button_parameters. label = 'Setup'
button_parameters. position = {0,0.5,0}
button_parameters. width = 500
button_parameters. height = 500
button_parameters. font_size = 100
button_parameters. font_color = {0,0,0}

function onload()
setupbutton = getObjectFromGUID(setupguid)
setupbutton.setName('Setup Button')
setupbutton.createButton(button_parameters)
end

function setupgame()
Print('Hello')
end


What I understand this should do is set setupguid to the correct GUID of the checker (I've double checked it's correct). Then it should create some button parameters and keep them in a table. Then on load it should set setupbutton variable to the code stored in setupguid. Then it should name the checker 'Setup Button'. Then it should create a Setup button over it. But I'm getting the following error:

Error in Script (Global) function <onload>: chunk_3:(18,19-35): attempt to index a nil value

It's falling over when it's trying to create the button. I'm aware that one of the values (Function Owner) has been set to nil but this is what I've been instructed to do in the guide. Another one instructed me to set it to Self. Either way the error still occurs so I'm assuming it's not that. Now I've read online that this occurs if you do something in global scripting instead of an object's scripting? But all the basic coding guides are telling me to do this, none of them mention putting any scripting code inside the checker itself. Please can someone explain what's happening here? Are these guides out-of-date and it now needs to be done a different way? I'm falling over at the first hurdle...

Any help greatly appreciated!
Last edited by Metalsech; Jan 21, 2021 @ 9:44am
< >
Showing 1-1 of 1 comments
Bone White Jan 22, 2021 @ 1:33am 
function_owner cannot be nil. In your situation, I expect it to be Global.
< >
Showing 1-1 of 1 comments
Per page: 1530 50