Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onSave()
- local data_to_save = {saved_count1 = countHP, saved_count2 = countMP}
- saved_data = JSON.encode(data_to_save)
- return saved_data
- end
- --Loads the saved data then creates the buttons
- function onload(saved_data)
- generateButtonParamitersHP()
- --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)
- countHP = loaded_data.saved_count1
- else
- --If there wasn't saved data, the default value is set to 10.
- countHP = 10
- end
- generateButtonParamitersMP()
- --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)
- countMP = loaded_data.saved_count2
- else
- --If there wasn't saved data, the default value is set to 10.
- countMP = 10
- end
- b_displayHP.label = tostring(countHP)
- b_displayHP.font_size = 70
- b_displayMP.label = tostring(countMP)
- b_displayMP.font_size = 70
- self.createButton(b_displayHP)
- self.createButton(b_plusHP)
- self.createButton(b_minusHP)
- self.createButton(b_plusHP5)
- self.createButton(b_minusHP5)
- self.createButton(b_displayMP)
- self.createButton(b_plusMP)
- self.createButton(b_minusMP)
- self.createButton(b_plusMP5)
- self.createButton(b_minusMP5)
- end
- function increaseMP()
- countMP = countMP + 1
- updateDisplayMP()
- end
- function decreaseMP()
- --Prevents countMP from going below 0
- if countMP > 0 then
- countMP = countMP - 1
- updateDisplayMP()
- end
- end
- function increaseMP5()
- countMP = countMP + 5
- updateDisplayMP()
- end
- function decreaseMP5()
- --Prevents countMP from going below 0
- if countMP > 4 then
- countMP = countMP - 5
- else
- countMP = 0
- end
- updateDisplayMP()
- end
- function customSetMP()
- local descriptionMP = self.getDescription()
- if descriptionMP != '' and type(tonumber(descriptionMP)) == 'number' then
- self.setDescription('')
- countMP = tonumber(descriptionMP)
- updateDisplayMP()
- end
- end
- function updateDisplayMP()
- b_displayMP.font_size = 70
- b_displayMP.label = tostring(countMP)
- self.editButton(b_displayMP)
- end
- function increaseHP()
- countHP = countHP + 1
- updateDisplayHP()
- end
- function decreaseHP()
- --Prevents countHP from going below 0
- if countHP > 0 then
- countHP = countHP - 1
- updateDisplayHP()
- end
- end
- function increaseHP5()
- countHP = countHP + 5
- updateDisplayHP()
- end
- function decreaseHP5()
- --Prevents countHP from going below 0
- if countHP > 4 then
- countHP = countHP - 5
- else
- countHP = 0
- end
- updateDisplayHP()
- end
- function customSetHP()
- local descriptionHP = self.getDescription()
- if descriptionHP != '' and type(tonumber(descriptionHP)) == 'number' then
- self.setDescription('')
- countHP = tonumber(descriptionHP)
- updateDisplayHP()
- end
- end
- function updateDisplayHP()
- b_displayHP.font_size = 70
- b_displayHP.label = tostring(countHP)
- self.editButton(b_displayHP)
- end
- function generateButtonParamitersHP()
- b_displayHP = {
- index = 0, click_function = 'customSetHP', function_owner = self, label = '',
- position = {0,0.1,0}, width = 600, height = 600, font_size = 500
- }
- b_plusHP = {
- click_function = 'increaseHP', function_owner = self, label = '+1',
- position = {0.75,0.1,0.26}, width = 150, height = 300, font_size = 100
- }
- b_minusHP = {
- click_function = 'decreaseHP', function_owner = self, label = '-1',
- position = {-0.75,0.1,0.26}, width = 150, height = 300, font_size = 100
- }
- b_plusHP5 = {
- click_function = 'increaseHP5', function_owner = self, label = '+5',
- position = {0.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
- }
- b_minusHP5 = {
- click_function = 'decreaseHP5', function_owner = self, label = '-5',
- position = {-0.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
- }
- end
- function generateButtonParamitersMP()
- b_displayMP = {
- index = 5, click_function = 'customSetMP', function_owner = self, label = '',
- position = {2,0.1,0}, width = 600, height = 600, font_size = 500
- }
- b_plusMP = {
- click_function = 'increaseMP', function_owner = self, label = '+1',
- position = {2.75,0.1,0.26}, width = 150, height = 300, font_size = 100
- }
- b_minusMP = {
- click_function = 'decreaseMP', function_owner = self, label = '-1',
- position = {-2.75,0.1,0.26}, width = 150, height = 300, font_size = 100
- }
- b_plusMP5 = {
- click_function = 'increaseMP5', function_owner = self, label = '+5',
- position = {2.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
- }
- b_minusMP5 = {
- click_function = 'decreaseMP5', function_owner = self, label = '-5',
- position = {-2.75,0.1,-0.29}, width = 150, height = 230, font_size = 100
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement