Author Topic: Simple dialog pause menu  (Read 9 times)

Miguelink 64

  • Newbie
  • *
  • Posts: 2
    • View Profile
Simple dialog pause menu
« on: November 13, 2018, 09:20:47 pm »
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
  1.   -- Event called when the game pauses
  2.   function game:on_paused()
  3.  
  4.     game:start_dialog("pause.menu.question",function(answer) -- Opens the "menu"
  5.  
  6.         if answer == 1 then -- Items
  7.  
  8.           if game:has_item("boomerang") == true then -- Checks if you have an item
  9.  
  10.             game:start_dialog("pause.menu.items.1",function(answer) -- Shows item
  11.  
  12.               if answer == 1 then
  13.  
  14.                 game:set_item_assigned(1,game:get_item("boomerang")) -- Assigns selected item to Slot 1
  15.  
  16.                 sol.audio.play_sound("danger")
  17.  
  18.                 game:set_paused(false)
  19.  
  20.               end
  21.  
  22.             end)
  23.  
  24.           else -- If you don't have items at all
  25.  
  26.             game:start_dialog("pause.menu.items.no_items")
  27.  
  28.             game:set_paused(false)
  29.  
  30.           end
  31.  
  32.         end
  33.  
  34.         if answer == 2 then -- Save and continue
  35.  
  36.           game:save()
  37.  
  38.           sol.audio.play_sound("danger")
  39.  
  40.           game:set_paused(false)
  41.  
  42.         end
  43.  
  44.         if answer == 3 then -- Save and Quit (Closes the game)
  45.  
  46.           sol.audio.play_sound("danger")
  47.  
  48.           game:save()
  49.  
  50.           sol.main.exit()
  51.  
  52.         end
  53.  
  54.         if answer == 4 then -- Continue
  55.  
  56.           sol.audio.play_sound("danger")
  57.  
  58.           game:set_paused(false)
  59.  
  60.         end
  61.  
  62.       end)
  63.  
  64.    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. ;)
« Last Edit: November 13, 2018, 09:25:54 pm by Miguelink 64 »