Author Topic: Help:: Question dialog does not return anything  (Read 1606 times)

poireau

  • Newbie
  • *
  • Posts: 1
    • View Profile
Help:: Question dialog does not return anything
« on: July 20, 2014, 06:12:29 pm »
Hello all!

I've recently started using Solarus and have been loosely following the tutorials. But when I get to the "ask if the player wants to save" part (chapter 5 in the french tut of the Wiki), I get a problem... the question doesn't return anything. Also the 2nd question is skipped, but I think the cause is the same

(I noticed because it didn't save. Also I need to press space once more after selecting the answer to get to the next step and unpause).

Here's the code I use:
in the game_manager
Code: [Select]
game.on_started = function()
game.dialog_box = dialog_box_builder:create(game)
sol.menu:start(game,game.dialog_box)
end

game.on_paused = function()
game:start_dialog("pause_menu", function(answer) -- DOES NOT RETURN ANYTHING. answer == nil

if answer == 1 then
game:save()
end
game:start_dialog("answer_"..answer) -- testing

game:start_dialog("pause_menu_2", function(answer) -- DOES NOT RETURN ANYTHING. answer == nil

if answer == 1 then
sol.main.reset()
end
game:start_dialog("answer_"..answer) -- testing
end)

end)

in dialogs.dat
Code: [Select]
dialog{
id = "pause_menu",
question = true,
text = [[
Sauvegarder la partie ?
Oui
Non
]]
}

-- pause_menu_2
dialog{
id = "pause_menu_2",
question = true,
text = [[
Quitter le jeu?
Oui
Non
]]
}

--answer was 1
dialog{
id = "answer_1",
text = [[
you answered: 1
]]
}

and I get these errors (first one is because dialog_box.lua is needed but empty at this point of the tutorial)
Code: [Select]
Error: In on_started: [string "scripts/game_manager.lua"]:18: attempt to index upvalue 'dialog_box_builder' (a boolean value)
Error: In dialog callback: [string "scripts/game_manager.lua"]:28: attempt to concatenate local 'answer' (a nil value)

As far as I can tell it looks exactly as it should... What am I doing wrong?

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1176
    • View Profile
Re: Help:: Question dialog does not return anything
« Reply #1 on: July 20, 2014, 06:38:06 pm »
Hi,
It might be because this chapter of the tutorial was made with an old release (1.0). The dialog system was built-in at that time. Since 1.1, it is customizable. It is your responsibility to pass any value to the callback, by calling game:stop_dialog(). If you don't use a customized dialog system, then a default, built-in dialog box is shown instead, but nothing is passed to the callback.

More details here:
http://www.solarus-games.org/doc/1.2/lua_api_game.html#lua_api_game_start_dialog

See also the tutorial about how to upgrade your quest from 1.0 to 1.1: https://www.youtube.com/watch?v=PKuc54i81GY&list=PLzJ4jb-Y0ufySXw9_E-hJzmzSh-PYCyG2&index=22