40 lines
910 B
Plaintext
40 lines
910 B
Plaintext
|
MIN_VALUE = -99
|
||
|
MAX_VALUE = 999
|
||
|
val = 0
|
||
|
|
||
|
function onSave() return JSON.encode(val) end
|
||
|
|
||
|
function onLoad(saved_data)
|
||
|
if saved_data ~= nil then
|
||
|
val = JSON.decode(saved_data)
|
||
|
end
|
||
|
|
||
|
self.createButton({
|
||
|
label = tostring(val),
|
||
|
click_function = "addOrSubtract",
|
||
|
function_owner = self,
|
||
|
position = { 0, 0.06, 0 },
|
||
|
height = 600,
|
||
|
width = 1000,
|
||
|
scale = { 1.5, 1.5, 1.5 },
|
||
|
font_size = 600,
|
||
|
font_color = { 1, 1, 1, 100 },
|
||
|
color = { 0, 0, 0, 0 }
|
||
|
})
|
||
|
end
|
||
|
|
||
|
function updateVal(newVal)
|
||
|
if tonumber(newVal) then
|
||
|
val = newVal
|
||
|
self.editButton({
|
||
|
index = 0,
|
||
|
label = tostring(val)
|
||
|
})
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function addOrSubtract(_, _, alt_click)
|
||
|
val = math.min(math.max(val + (alt_click and -1 or 1), MIN_VALUE), MAX_VALUE)
|
||
|
self.editButton({ index = 0, label = tostring(val) })
|
||
|
end
|