Dialog problems

Started by Zeror, August 19, 2015, 12:45:58 PM

Previous topic - Next topic
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.

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().

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

Ok, this is exactly the error I was referring to.

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.

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.

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

In line 11, instead of "oldman_helped_4B = true", try to use "game:set_value("oldman_helped_4B", true)". That will probably work.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

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.