Tabletop Simulator

Tabletop Simulator

View Stats:
TDP Jan 1, 2019 @ 6:00am
how to enable/disable a button on an object?
I have made 4 buttons on an object to move an RPGFigurine. but if I click on a button too fast it doesnt move correctly. Is there a way to disable button as soon as pressed and as soon as the setPositionSmooth command is done enable it again? This might also be possible with a button cooldown if there is such a thing. Any ideas?
< >
Showing 1-6 of 6 comments
Bone White Jan 2, 2019 @ 1:33am 
Buttons are indexed on creation. The way I toggle buttons on/off is I save the buttons to a local table, and create them in a function called e.g. showButtons() by looping through the table (called in onLoad() and others)

On pressing any button, the first thing that function does is call clearButtons() on the object, then do all the work (maybe with a delay from a startLuaCoroutine() or Wait.time()), then when it's finished I call showButtons() again.

You could dynamically build your buttons table to exclude a certain number e.g. when pressing button 1, the table will be built with all buttons but the button at index 1 in your button table, and then after the delay, clear the buttons and show them all.
TDP Jan 2, 2019 @ 6:41am 
thanks but then- where are the buttons indexed, and how do I find them? I have made 5 buttons on an object to move my RPGFigurine and one of them to attack, but I dont knnow what the buttons are called. I only say .createButton not how the button should be called...

EDIT:
nvm I'll use your method
Last edited by TDP; Jan 2, 2019 @ 6:59am
TDP Jan 2, 2019 @ 6:59am 
how do I call a function in global? is it global.showButtons()?
Bone White Jan 3, 2019 @ 1:51am 
Global.call("showButtons")

https://api.tabletopsimulator.com/object/#call

Buttons are always made at the first "free" index, with no return value coming from createButton makes it tricky to store which button is kept at which index. I find it easier to just clear the buttons and remake them, excluding the one i wish to omit.

You can pull a table of the buttons on an object using getButtons()

https://api.tabletopsimulator.com/object/#getbuttons
Last edited by Bone White; Jan 3, 2019 @ 1:53am
TDP Jan 4, 2019 @ 4:27am 
as what are the buttons saved in the showButtons table, do I say like for example knight.getButtons().1 as the first created button or what? and thanks for your help it is deeply appreciated
Bone White Jan 4, 2019 @ 7:10am 
knight.getButtons()[1] would be the first created button yes. Though this is only true for buttons created sequentially (e.g. not inside a croutine e.g. startLuaCoroutine()), and will get annoyingly unreliable to predict if you use removeButton() and then create further buttons.

If you're ever unsure of what data you're dealing with, use log(knight.getButtons()) in your code, then in the log part of your chat window (looks like a ~ symbol) it'll show you the structure of the data to help you work with it. This would show you that getButtons() returns an array with numerical indexes. You can't access numerical indexes with the . syntax, only putting the number in [] will work. (this is because named variables cannot begin with a number in Lua)
< >
Showing 1-6 of 6 comments
Per page: 1530 50

Date Posted: Jan 1, 2019 @ 6:00am
Posts: 6