Author Topic: Trouble with dialog function syntax  (Read 1218 times)

Starlock

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Trouble with dialog function syntax
« on: August 24, 2016, 07:15:38 pm »
Hey, I started working on the dialog box for the level up system, and it is supposed to show a dialog that allows you to pick a stat to boost, but if a stat is maxed out, it will show a dialog allowing to boost the other two, and if two are maxed out, it should boost the last stat. I've tried multiple different things, and it continues to just show the same dialog, so I decided it might be easier to ask on the forums.

This is the chunk of code:

Code: ( lua) [Select]
-- Level up
  if self.current_xp_displayed >= xp_to_levelup then
self.game:set_value("current_level", current_level + 1)
difference = current_xp - xp_to_levelup
self.game:set_value("current_xp", difference)
current_xp = self.game:get_value("current_xp")
self.current_xp_displayed = 0
self.current_xp_displayed_length = string.len(self.current_xp_displayed)
    self.game:start_dialog("levelup", current_level + 1, function()
      if self.game:get_max_life(60) then
        self.game:start_dialog("leveluphealthmax", function(answer)
          if answer == 2 then
            self.game:start_dialog("levelupmana", self.game:get_max_magic() + 10)
            self.game:set_max_magic(self.game:get_max_magic() + 10)
            self.game:set_magic(self.game:get_max_magic())
          elseif answer == 3 then
            self.game:start_dialog("levelupstamina", self.game:get_max_stamina() + 10)
            self.game:set_max_stamina(self.game:get_max_stamina() + 10)
            self.game:set_stamina(self.game:get_max_stamina())
        end
      end)
      elseif self.game:get_max_magic(200) then
        self.game:start_dialog("levelupmanamax", function(answer)
          if answer == 2 then
            self.game:start_dialog("leveluphealth", self.game:get_max_life(), self.game:get_max_life())
            self.game:add_max_life(5)
            self.game:set_life(game:get_max_life())
          elseif answer == 3 then
            self.game:start_dialog("levelupstamina", self.game:get_max_stamina(), self.game:get_max_stamina())
            self.game:add_max_stamina(10)
            self.game:set_stamina(game:get_max_stamina())
         end
       end)
      elseif self.game:get_max_stamina(200) then
        self.game:start_dialog("levelupstaminamax", function(answer)
          if answer == 2 then
            self.game:start_dialog("leveluphealth", self.game:get_max_life(), self.game:get_max_life())
            self.game:add_max_life(5)
            self.game:set_life(game:get_max_life())
          elseif answer == 3 then
            self.game:start_dialog("levelupmagic", self.game:get_max_magic(), self.game:get_max_magic())
            self.game:add_max_magic(10)
            self.game:set_magic(game:get_max_magic())
      elseif self.game:get_max_life(60) and
             self.game:get_max_magic(200) then
               self.game:start_dialog("levelupstamina", self.game:get_max_stamina(), self.game:get_max_stamina())
               self.game:add_max_stamina(10)
               self.game:set_stamina(game:get_max_stamina())
      elseif self.game:get_max_life(60) and
             self.game:get_max_stamina(200) then
               self.game:start_dialog("levelupmagic", self.game:get_max_magic(), self.game:get_max_magic())
               self.game:add_max_magic(10)
               self.game:set_magic(game:get_max_magic())
      elseif self.game:get_max_magic(200) and
             self.game:get_max_stamina(200) then
               self.game:start_dialog("leveluphealth", self.game:get_max_life(), self.game:get_max_life())
               self.game:add_max_life(5)
               self.game:set_life(game:get_max_life())
            end
         end)
      else self.game:start_dialog("levelupall", function(answer)
          if answer == 2 then
            self.game:start_dialog("leveluphealth", self.game:get_max_life(), self.game:get_max_life())
            self.game:add_max_life(5)
            self.game:set_life(game:get_max_life())
          elseif answer == 3 then
            self.game:start_dialog("levelupmagic", self.game:get_max_magic(), self.game:get_max_magic())
            self.game:add_max_magic(10)
            self.game:set_magic(game:get_max_magic())
          elseif answer == 4 then
            self.game:start_dialog("levelupstamina", self.game:get_max_stamina(), self.game:get_max_stamina())
            self.game:add_max_stamina(10)
            self.game:set_stamina(game:get_max_stamina())
         end
       end)
end
end)
end
end

Diarandor

  • Hero Member
  • *****
  • Posts: 1047
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Trouble with dialog function syntax
« Reply #1 on: August 24, 2016, 07:50:32 pm »
Where you wrote
Code: [Select]
if self.game:get_max_life(60) then the code should be like this:
Code: [Select]
if self.game:get_max_life() == 60 then There are more "if" conditions with the same mistake.
I hope this solves the problem.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Starlock

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Re: Trouble with dialog function syntax
« Reply #2 on: August 24, 2016, 08:31:01 pm »
Thank you, Diarandor. That worked to solve the problem.    :D