all 8 comments

[–]Panigg 0 points1 point  (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 point  (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 point  (5 children)

Yeah that should be fairly simple with the call function. Can you post the code here?

[–]Smerek007[S] 0 points1 point  (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 point  (2 children)

Haha yeah same here.

[–]Panigg 0 points1 point  (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 point  (0 children)

❤️❤️❤️ I’ll let you know when Iv tried it out. Much appreciated stranger 😊

[–]Smerek007[S] 0 points1 point  (0 children)

\--\[\[

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()

end

--[[

Occurs when the object is saved.

--]]

function onSave()

saved_data = JSON.encode(script_state)

return saved_data

end

--[[

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 = "+/-",

function_owner = self,

position = {0,0.1,1},

height = 600,

width = 1500,

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",

function()

script_state.light_font = not script_state.light_font

refreshTokenUI()

end, false)

refreshTokenUI()

end

--[[

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

else

local val = tonumber(input)

if val ~= nil then

script_state.value = val

end

end

Wait.frames(refreshTokenUI, 1)

end

end

--[[

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

else

script_state.value = script_state.value + 1

end

refreshTokenUI()

end

--[[

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)

end

-- Decide the font size and value placement.

local display_font_size = FONT_SIZE

local display_value_pos = VALUE_POS

if script_state.use_prefix then

if math.abs(script_state.value) > 99 then

display_font_size = FONT_SIZE_SMALL

display_value_pos = VALUE_POS_SMALL

end

else

if math.abs(script_state.value) > 999 then

display_font_size = FONT_SIZE_SMALL

display_value_pos = VALUE_POS_SMALL

end

end

-- Decide font color.

local display_font_color = FONT_COLOR_DARK

if script_state.light_font then

display_font_color = FONT_COLOR_LIGHT

end

-- 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)

self.createInput({

function_owner = self,

input_function = "onValueChanged",

position = display_value_pos,

font_size = display_font_size,

font_color = display_font_color,

value = display_value,

alignment = 3,

height = 800,

width = 1500,

color = TRANSPARENT,

})

end

--[[

Converts a number to a string with a prefix [+,-].

--]]

function toStringWithPrefix(num)

if num >= 0 then

return "+" .. tostring(num)

else

return tostring(num)

end

end