Advertisement
MrStump

Untitled

Aug 28th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. function onSave()
  2.     saved_data = JSON.encode(ref_checkboxes)
  3.     --saved_data=""
  4.     return saved_data
  5. end
  6.  
  7. function onload(saved_data)
  8.     --Loads the tracking for if the game has started yet
  9.     if saved_data ~= "" then
  10.         local loaded_data = JSON.decode(saved_data)
  11.         ref_checkboxes = loaded_data
  12.     else
  13.         ref_checkboxes = {
  14.             {pos={0,0.1,0}, state=false},
  15.             {pos={1,0.1,0}, state=false},
  16.             {pos={2,0.1,0}, state=false},
  17.         }
  18.     end
  19.  
  20.     createCheckboxes()
  21. end
  22.  
  23. function createCheckboxes()
  24.     for i, boxData in ipairs(ref_checkboxes) do
  25.         --Set up the function trigger
  26.         local funcName = "checkbox"..i
  27.         local func = function() toggleCheck(i) end
  28.         self.setVar(funcName, func)
  29.         --Set the X
  30.         local label = ""
  31.         if boxData.state == true then label = "X" end
  32.         --Make the button
  33.         self.createButton({
  34.             click_function = funcName, function_owner = self, label = label,
  35.             position =boxData.pos, width = 150, height = 150, font_size = 145,
  36.             scale = {0.1,0.1,0.1}
  37.         })
  38.     end
  39. end
  40.  
  41. function toggleCheck(i)
  42.     if ref_checkboxes[i].state == true then
  43.         self.editButton({index=i-1, label=""})
  44.         ref_checkboxes[i].state = false
  45.     else
  46.         self.editButton({index=i-1, label="X"})
  47.         ref_checkboxes[i].state = true
  48.     end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement