Simple Dialog Pause Menu

Started by Miguelink 64, November 13, 2018, 04:14:09 PM

Previous topic - Next topic
November 13, 2018, 04:14:09 PM Last Edit: November 13, 2018, 09:27:42 PM by Miguelink 64
Hi, I'm new in programming and I've recently discovered solarus, I've seen all Cristopho's tutorials so I started to make my own game, since Cristopho doesn't explain how to make a pause menú (only how to save with dialogs) I decided to make my own pause menu, but i lack the knowledge to do it, so i made a simple one that doesn't require to code a menu, only using the alttp dialog box system the pack already has, this is the code.


Code ( lua) Select
  -- Event called when the game pauses
  function game:on_paused()

    game:start_dialog("pause.menu.question",function(answer) -- Opens the "menu"

        if answer == 1 then -- Items

          if game:has_item("boomerang") == true then -- Checks if you have an item

            game:start_dialog("pause.menu.items.1",function(answer) -- Shows item

              if answer == 1 then

                game:set_item_assigned(1,game:get_item("boomerang")) -- Assigns selected item to Slot 1

                sol.audio.play_sound("danger")

                game:set_paused(false)

              end

            end)

          else -- If you don't have items at all

            game:start_dialog("pause.menu.items.no_items")

            game:set_paused(false)

          end

        end

        if answer == 2 then -- Save and continue

          game:save()

          sol.audio.play_sound("danger")

          game:set_paused(false)

        end

        if answer == 3 then -- Save and Quit (Closes the game)

          sol.audio.play_sound("danger")

          game:save()

          sol.main.exit()

        end

        if answer == 4 then -- Continue

          sol.audio.play_sound("danger")

          game:set_paused(false)

        end

      end)

   end



If you want to copy it, paste it on the game_manager.lua script, under game:start() , add some dialog on your languages folder using the $? thing to make selectable text and thats it.
The only thing is that you must have to collect the equipment in order, and add a new dialog with all previous ítems + the new one, also do a new if-else over the already writen code, but at least you now have your pause menu. ;)