Author Topic: Dialog problems  (Read 2202 times)

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Dialog problems
« 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.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile
Re: Dialog problems
« Reply #1 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().

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Dialog problems
« Reply #2 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

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile
Re: Dialog problems
« Reply #3 on: August 19, 2015, 12:57:26 pm »
Ok, this is exactly the error I was referring to.

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Dialog problems
« Reply #4 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.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile
Re: Dialog problems
« Reply #5 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.

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Dialog problems
« Reply #6 on: August 19, 2015, 08:21:52 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

Diarandor

  • Hero Member
  • *****
  • Posts: 1044
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dialog problems
« Reply #7 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.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Dialog problems
« Reply #8 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.