Solarus-Games English Forum

Solarus => Development => Topic started by: Zeror on August 19, 2015, 12:45:58 PM

Title: Dialog problems
Post by: Zeror on August 19, 2015, 12:45:58 PM
I'm trying to create an advanced dialog, but i can't get it work.

I got this:
Code (lua) Select
local map = ...
local game = map:get_game()

function oldman_npc:on_interaction()                            -- oldman_npc is the name of the NPC

  if not game:get_value("4b_oldman_helped") then
    game:start_dialog("oldmans_cave.question", function(answer) -- Old mans asks a YES/NO question
    if answer == 2 then
      game:start_dialog("oldmans_cave.answer1", function()      -- Answer YES >> Get 20 rupees
        hero:start_treasure("rupee", 3, "4b_oldman_helped")
        4b_oldman_helped = true
      end)
    else                                                        -- Answer NO
      game:start_dialog("oldmans_cave.answer2")
      return
    end)
  else
    game:start_dialog("oldmans_cave.done")                      -- Old man refers to the 20 rupees he gave.
    return
  end

end


Why is this not working? I don't get a dialog at all when hitting the action key in front of the NPC.
Title: Re: Dialog problems
Post by: Christopho on August 19, 2015, 12:49:19 PM
As always, do you have an error message?

At line 11, 4b_oldman_helped is not a valid Lua variable name. It cannot start by a digit.
It should not be accepted by the engine either in game:get_value() or hero:start_treasure().
Title: Re: Dialog problems
Post by: Zeror on August 19, 2015, 12:52:39 PM
I got an error:

Error: Failed to load script 'maps/interior_4B/oldmanscave': [string "maps/interior_4B/oldmanscave.lua"]:11: malformed number near '4b_oldman_helped'
Error: In maps/interior_4B/oldmanscave: attempt to call a string value
Title: Re: Dialog problems
Post by: Christopho on August 19, 2015, 12:57:26 PM
Ok, this is exactly the error I was referring to.
Title: Re: Dialog problems
Post by: Zeror on August 19, 2015, 01:15:48 PM
OK, changed that to oldman_helped_4B instead.

Now this error:
Error: Failed to load script 'maps/interior_4B/oldmanscave': [string "maps/interior_4B/oldmanscave.lua"]:16: unexpected symbol near ')'
Error: In maps/interior_4B/oldmanscave: attempt to call a string value

Still no dialog btw.
Title: Re: Dialog problems
Post by: Christopho on August 19, 2015, 01:23:32 PM
Learn how to read Lua error messages ;)
You have a syntax error at line 16. There is no "end" of the function started line 7.
Title: Re: Dialog problems
Post by: Zeror on August 19, 2015, 08:21:52 PM
Quote from: Christopho on August 19, 2015, 01:23:32 PM
Learn how to read Lua error messages ;)
You have a syntax error at line 16. There is no "end" of the function started line 7.
I got it almost working now.

Code (lua) Select
local map = ...
local game = map:get_game()

function oldman_npc:on_interaction()                              -- oldman_npc is the name of the NPC

  if not game:get_value("oldman_helped_4B") then
    game:start_dialog("oldmans_cave.question", function(answer)   -- Old mans asks a YES/NO question
      if answer == 2 then
        game:start_dialog("oldmans_cave.answer1", function()      -- Answer YES >> Get 20 rupees
          hero:start_treasure("rupee", 3, "oldman_helped_4B")
          oldman_helped_4B = true
        end)
      else                                                        -- Answer NO
        game:start_dialog("oldmans_cave.answer2")
        return
      end
    end)
  else
    game:start_dialog("oldmans_cave.done")                        -- Old man refers to the 20 rupees he gave.
    return
  end

end


The ELSE part starting on line 18 or the part where to save a variable does not work yet. I am not seeing the variable in the quest.dat
Title: Re: Dialog problems
Post by: Diarandor on August 19, 2015, 09:39:02 PM
In line 11, instead of "oldman_helped_4B = true", try to use "game:set_value("oldman_helped_4B", true)". That will probably work.
Title: Re: Dialog problems
Post by: Zeror on August 19, 2015, 10:29:10 PM
I am wondering if don't need something else to get the variable data saved.

I did the change, but i still don't get the done dialog.