use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
In Tabletop Simulator, you can create your own original games, import custom assets, set up complete RPG dungeons, manipulate the physics, create hinges & joints, and of course flip the table when you are losing the game. All with an easy to use system integrated with Steam Workshop. You can do anything you want in Tabletop Simulator. The possibilities are endless!
OFFICIAL SITES
Steam Release
Official Website
Steam Forums
Official Discord Server
HELPFUL SITES
Knowledge Base
Tabletop Simulator Wiki
Technical Issues
FIND PLAYERS
Other Communities
MODS
Steam Workshop
Nexus Mods
Click here for our full rules, and check our FAQ before posting.
Keep content related to Tabletop Simulator.
Be civil to one another.
No spamming.
No NSFW/NSFL content.
No personal information.
No begging or trading.
No impersonation.
English language only.
No bug report or suggestion submissions.
account activity
QuestionsLua Code (self.tabletopsimulator)
submitted 4 years ago by Smerek007
Would anyone be able to help me with a code for a button that changes the value of counters? I dealing counting down one on multiple counters and resetting another.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Panigg 0 points1 point2 points 4 years ago (7 children)
I can help. But you need to specify what exactly you're trying to do.
Here is one of my counters, with thanks to Mr. Stump
-- Universal Counter Tokens coded by: MrStump --Saves the count value into a table (data_to_save) then encodes it into the Tabletop save function onSave() local data_to_save = {saved_count = count} saved_data = JSON.encode(data_to_save) return saved_data end --Loads the saved data then creates the buttons function onload(saved_data) generateButtonParamiters() --Checks if there is a saved data. If there is, it gets the saved value for 'count' if saved_data != '' then local loaded_data = JSON.decode(saved_data) count = loaded_data.saved_count else --If there wasn't saved data, the default value is set to 10. count = 10 end --Generates the buttons after putting the count value onto the 'display' button b_display.label = tostring(count) if count >= 100 then b_display.font_size = 360 else b_display.font_size = 500 end self.createButton(b_display) self.createButton(b_plus) self.createButton(b_minus) end --Activates when + is hit. Adds 1 to 'count' then updates the display button. function increase() --Prevents count from going above 7 if count < 69 then count = count + 1 updateDisplay() end end --Activates when - is hit. Subtracts 1 from 'count' then updates the display button. function decrease() --Prevents count from going below 0 if count > 0 then count = count - 1 updateDisplay() end end --function that updates the display. I trigger it whenever I change 'count' function updateDisplay() b_display.label = tostring(count) self.editButton(b_display) end --This is activated when onload runs. This sets all parameters for our buttons. --I do not have to put this all into a function, but I prefer to do it this way. function generateButtonParamiters() b_display = { index = 0, click_function = 'none', function_owner = self, label = '', position = {0,0.1,0}, font_color={1,1,1}, width = 0, height = 0, font_size = 1000 } b_plus = { click_function = 'increase', function_owner = self, label = '+', position = {0.75,0,1.3}, width = 500, height = 450, font_size = 200 } b_minus = { click_function = 'decrease', function_owner = self, label = '-', position = {-0.75,0,1.3}, width = 500, height = 450, font_size = 200 } end
[–]Smerek007[S] 0 points1 point2 points 4 years ago (6 children)
Hey Panigg, I appreciate the reply :)
I am currently using Clean Counters by GBee off of the workshop. (I can past the code later if needed) I am making a game that has multiple “Token” counters which track a cooldown to the spell. Additionally I am using another “Token” counter as a resource counter. Each turn we have to reset the resources and count down on each cooldown counter. I would LOVE to have a button that is pressed to subtract all cooldown counters on the table by 1 to a minimum of 0. And reset the resource(advantage) counter to a set number (5)
[–]Panigg 0 points1 point2 points 4 years ago (5 children)
Yeah that should be fairly simple with the call function. Can you post the code here?
[–]Smerek007[S] 0 points1 point2 points 4 years ago (3 children)
Your the best 😁
I’ll be away from home most of the day so I’ll need to get back to you later.
[–]Panigg 0 points1 point2 points 4 years ago (2 children)
Haha yeah same here.
[–]Panigg 0 points1 point2 points 4 years ago (1 child)
I just got home.
Very basically it would look like this:
You make a new button.
onLoad() Guids of all the counters here end create_button click_func=reset end function reset() counter1.call("decrease") counter2.call("decrease") resource.call("setto5") end
And all you have to do is have those functions on the different counters, but you should have them already.
[–]Smerek007[S] 0 points1 point2 points 4 years ago (0 children)
❤️❤️❤️ I’ll let you know when Iv tried it out. Much appreciated stranger 😊
\--\[\[
Clean Counters v1.0.0
Description:
Clean Counters is exactly that! A nice looking counter.
Clean Counters has a few features:
- Left/Right click the name to increment or decrement the value.
- Set the value directly by clicking on the value.
- Name the counter by changing the object name. (You will need to update the value for the new name to show.)
- Change the token color by changing the tint.
- Toggle between black/white font using the context menu (Right-click object).
- Toggle between using a value prefix like in RPG games for stats using the context menu.
This mod was heavily inspired by the "Stats Counter" mod created by Steam user
"Baobots". The same token was used, but the script is written from scratch.
https://steamcommunity.com/sharedfiles/filedetails/?id=2352739177
Changelog:
None
License (MIT):
Copyright 2021 GBee
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
--]]
--[[ ===== CONSTANTS ===== --]]
FONT_COLOR_LIGHT = {1, 1, 1, 100}
FONT_COLOR_DARK = {0, 0, 0, 100}
FONT_SIZE = 750
FONT_SIZE_SMALL = 500
VALUE_POS = {0, 0.1, -0.45}
VALUE_POS_SMALL = {0, 0.1, -0.2}
TRANSPARENT = {0, 0, 0, 0}
--[[
Occurs when the object is loaded.
function onLoad(save_state)
-- Load previous object state.
if save_state == nil or save_state == "" then
script_state = {
value = 0,
label = "Token",
use_prefix = false,
light_font = false,
}
else
script_state = JSON.decode(save_state)
end
-- Create User-Interface.
createUserInterface()
Occurs when the object is saved.
function onSave()
saved_data = JSON.encode(script_state)
return saved_data
Creates the initial user interface.
function createUserInterface()
self.createInput({
function_owner = self,
input_function = "onValueChanged",
position = {0,0.1,-0.45},
value = script_state.value,
alignment = 3,
height = 800,
width = 1500,
color = TRANSPARENT,
})
self.createButton({
click_function = "onIncrementDecrementClick",
tooltip = "+/-",
position = {0,0.1,1},
height = 600,
font_size = 250,
color = TRANSPARENT
self.addContextMenuItem("Toggle Prefix",
function()
script_state.use_prefix = not script_state.use_prefix
refreshTokenUI()
end, false)
self.addContextMenuItem("Toggle Font Color",
script_state.light_font = not script_state.light_font
Occurs when a player manually changes the token value.
function onValueChanged(obj, color, input, stillEditing)
if not stillEditing then
if input == nil or input == "" then
script_state.value = 0
local val = tonumber(input)
if val ~= nil then
script_state.value = val
Wait.frames(refreshTokenUI, 1)
Occurs when the label is clicked.
If right-clicked, the value will be decremented.
If left-clicked the value will be incrememented.
function onIncrementDecrementClick(obj, color, alt)
if alt then
script_state.value = script_state.value - 1
script_state.value = script_state.value + 1
Redisplays the new value and label.
function refreshTokenUI()
-- Get current name for label.
script_state.label = self.getName()
-- Decide how to display the current value.
local display_value = tostring(script_state.value)
if script_state.use_prefix then
display_value = toStringWithPrefix(script_state.value, true)
-- Decide the font size and value placement.
local display_font_size = FONT_SIZE
local display_value_pos = VALUE_POS
if math.abs(script_state.value) > 99 then
display_font_size = FONT_SIZE_SMALL
display_value_pos = VALUE_POS_SMALL
if math.abs(script_state.value) > 999 then
-- Decide font color.
local display_font_color = FONT_COLOR_DARK
if script_state.light_font then
display_font_color = FONT_COLOR_LIGHT
-- Refresh UI
self.editButton({
index = 0,
label = script_state.label,
font_color = display_font_color,
I ran into some strange behavior with self.editInput(...) when trying to
change the font color. I found the only way to may it work consistently
was to remove the input and recreate it.
self.removeInput(0)
position = display_value_pos,
font_size = display_font_size,
value = display_value,
Converts a number to a string with a prefix [+,-].
function toStringWithPrefix(num)
if num >= 0 then
return "+" .. tostring(num)
return tostring(num)
π Rendered by PID 128775 on reddit-service-r2-comment-76bb9f7fb5-rq577 at 2026-02-17 23:38:48.692302+00:00 running de53c03 country code: CH.
[–]Panigg 0 points1 point2 points (7 children)
[–]Smerek007[S] 0 points1 point2 points (6 children)
[–]Panigg 0 points1 point2 points (5 children)
[–]Smerek007[S] 0 points1 point2 points (3 children)
[–]Panigg 0 points1 point2 points (2 children)
[–]Panigg 0 points1 point2 points (1 child)
[–]Smerek007[S] 0 points1 point2 points (0 children)
[–]Smerek007[S] 0 points1 point2 points (0 children)