Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MIN_VALUE = 0
- MAX_VALUE = 50
- value = 0
- backValue = 0
- f_size = 600
- function updateSave()
- local data_to_save = {value, backValue}
- saved_data = JSON.encode(data_to_save)
- self.script_state = saved_data
- end
- function onload(saved_data)
- if saved_data ~= "" then
- local loaded_data = JSON.decode(saved_data)
- --Set up information off of loaded_data
- if loaded_data[1] ~= nil then value = loaded_data[1] else value = MIN_VALUE end
- if loaded_data[2] ~= nil then backValue = loaded_data[2] else backValue = MIN_VALUE end
- else
- --Set up information for if there is no saved saved data
- value = MIN_VALUE
- backValue = MIN_VALUE
- end
- createBtns()
- end
- --Beginning Setup
- --Make setup button
- function createBtns()
- local pos = { - 0.9, 0.5, - 1.1}
- local backPos = {0.9, - 0.5, - 1.1}
- local rot = {0, 0, 0}
- local backRot = {0, 0, 180}
- local h = 500
- local w = 500
- local f_color = {1, 1, 1, 255}
- local bg_color = {0, 0, 0, 0}
- local diff = 0.8
- --center display
- self.createButton({
- label = tostring(value),
- click_function = "add_subtract",
- function_owner = self,
- position = pos,
- rotation = rot,
- height = h,
- width = w,
- scale = {x = 0.25, y = 0.25, z = 0.25},
- font_size = get_size(value),
- color = f_size,
- font_color = f_color,
- color = bg_color
- })
- --Back Side
- self.createButton({
- label = tostring(backValue),
- click_function = "add_subtract_back",
- function_owner = self,
- position = backPos,
- rotation = backRot,
- height = h,
- width = w,
- scale = {x = 0.25, y = 0.25, z = 0.25},
- font_size = get_size(value),
- color = f_size,
- font_color = f_color,
- color = bg_color
- })
- end
- function get_size(value)
- local char_count = string.len(tostring(value))
- return f_size * 2 / (char_count + 1)
- end
- function add_subtract(_obj, _color, alt_click)
- mod = alt_click and - 1 or 1
- new_value = math.min(math.max(value + mod, MIN_VALUE), MAX_VALUE)
- if value ~= new_value then
- value = new_value
- updateDisplay()
- updateSave()
- end
- end
- function add_subtract_back(_obj, _color, alt_click)
- mod = alt_click and - 1 or 1
- new_value = math.min(math.max(backValue + mod, MIN_VALUE), MAX_VALUE)
- if backValue ~= new_value then
- backValue = new_value
- updateDisplay()
- updateSave()
- end
- end
- function updateDisplay()
- self.editButton({
- index = 0,
- label = tostring(value),
- font_size = get_size(value)
- })
- self.editButton({
- index = 1,
- label = tostring(backValue),
- font_size = get_size(backValue)
- })
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement