Advertisement
kensuaga

CH toggle buttons

Aug 28th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. function onSave()
  2. saved_boxdata = JSON.encode(ref_checkboxes)
  3. --saved_boxdata=""
  4. return saved_boxdata
  5. end
  6.  
  7. function onload(saved_boxdata)
  8. --Loads the tracking for if the game has started yet
  9. saved_boxdata=""
  10. if saved_boxdata ~= "" then
  11. local loaded_data = JSON.decode(saved_boxdata)
  12. ref_checkboxes = loaded_data
  13. else
  14. ref_checkboxes = {
  15.  
  16. --Notes Section
  17. {pos={0.211,0.1,0.386}, state=false},
  18. {pos={0.257,0.1,0.386}, state=false},
  19. {pos={0.302,0.1,0.386}, state=false},
  20.  
  21. {pos={0.409,0.1,0.386}, state=false},
  22. {pos={0.455,0.1,0.386}, state=false},
  23. {pos={0.500,0.1,0.386}, state=false},
  24.  
  25. {pos={0.606,0.1,0.386}, state=false},
  26. {pos={0.652,0.1,0.386}, state=false},
  27. {pos={0.697,0.1,0.386}, state=false},
  28.  
  29. {pos={0.211,0.1,0.445}, state=false},
  30. {pos={0.257,0.1,0.445}, state=false},
  31. {pos={0.302,0.1,0.445}, state=false},
  32.  
  33. {pos={0.409,0.1,0.445}, state=false},
  34. {pos={0.455,0.1,0.445}, state=false},
  35. {pos={0.500,0.1,0.445}, state=false},
  36.  
  37. {pos={0.606,0.1,0.445}, state=false},
  38. {pos={0.652,0.1,0.445}, state=false},
  39. {pos={0.697,0.1,0.445}, state=false},
  40.  
  41. --Perks Section
  42. {pos={0.163,0.1,-0.801}, state=false},
  43. {pos={0.212,0.1,-0.801}, state=false},
  44.  
  45. {pos={0.163,0.1,-0.726}, state=false},
  46.  
  47. {pos={0.163,0.1,-0.651}, state=false},
  48.  
  49. {pos={0.163,0.1,-0.527}, state=false},
  50.  
  51. {pos={0.163,0.1,-0.403}, state=false},
  52. {pos={0.212,0.1,-0.403}, state=false},
  53.  
  54. {pos={0.163,0.1,-0.276}, state=false},
  55. {pos={0.212,0.1,-0.276}, state=false},
  56.  
  57. {pos={0.163,0.1,-0.198}, state=false},
  58.  
  59. {pos={0.163,0.1,-0.123}, state=false},
  60. {pos={0.212,0.1,-0.123}, state=false},
  61.  
  62. {pos={0.163,0.1,-0.002}, state=false},
  63.  
  64. {pos={0.163,0.1,0.076}, state=false},
  65.  
  66. {pos={0.163,0.1,0.183}, state=false},
  67.  
  68.  
  69.  
  70.  
  71.  
  72. }
  73. end
  74.  
  75.  
  76.  
  77. createCheckboxes()
  78. end
  79.  
  80. function createCheckboxes()
  81. --print('createCheckboxes funcatoin has been called')
  82. for i, boxData in ipairs(ref_checkboxes) do
  83. --Set up the function trigger
  84. local funcName = "checkbox"..i
  85. local func = function() toggleCheck(i) end
  86. self.setVar(funcName, func)
  87. --Set the X
  88. local label = ""
  89. print(tostring(label))
  90. if boxData.state == true then label = "X" end
  91. --Make the button
  92. self.createButton({
  93. click_function = funcName, function_owner = self, label = label,
  94. position =boxData.pos, width = 150, height = 150, font_size = 145,
  95. scale = {0.1,0.1,0.1}
  96. })
  97. end
  98. end
  99.  
  100. function toggleCheck(i)
  101. if ref_checkboxes[i].state == true then
  102. self.editButton({index=i-1, label=""})
  103. ref_checkboxes[i].state = false
  104. else
  105. self.editButton({index=i-1, label="X"})
  106. ref_checkboxes[i].state = true
  107. end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement