Author Topic: menubar.sc  (Read 2979 times)

0 Members and 1 Guest are viewing this topic.

Offline robingravel

menubar.sc
« on: September 16, 2003, 06:05:07 PM »
Hi folks

I wish to add a command list in my game.

In game.sh:

Quote

// Menu IDs eg. $302 means third menu, second item
(define MENU_ABOUT         $101)
(define MENU_HELP         $102)
(define MENU_LIST         $103) // added this one
(define MENU_RESTART      $201)
(define MENU_SAVE         $202)
(define MENU_RESTORE      $203)
(define MENU_QUIT         $205)
(define MENU_PAUSE         $301)
(define MENU_INVENTORY      $302)
(define MENU_RETYPE         $303)
(define MENU_COLOURS      $305)
(define MENU_CHANGESPEED   $401)
(define MENU_FASTERSPEED   $403)
(define MENU_NORMALSPEED   $404)
(define MENU_SLOWERSPEED   $405)
(define MENU_VOLUME         $501)
(define MENU_TOGGLESOUND   $502)




Offline robingravel

Re:menubar.sc
« Reply #1 on: September 16, 2003, 06:10:08 PM »
In menubar.sc:

Quote
/******************************************************************************
 menubar.sc
 Contains the customized Menubar class. This is the script you modify if you
 want to customize the menu.
 ******************************************************************************/
(include "sci.sh")
(include "game.sh")
/******************************************************************************/
(script MENUBAR_SCRIPT)
/******************************************************************************/
(use "main")
(use "controls")
(use "gauge")
(use "sound")
(use "user")
/******************************************************************************/
(class TheMenuBar of MenuBar
   (properties
      state 0
   )
   (method (init)
      AddMenu(
         "  "
            "About Template`^a:"+
            "Help`#1"
            "Command list`#6"
      )
      AddMenu(
         " File "
            "Restart Game`#9:"+
            "Save Game`#5:"+
            "Restore Game`#7:"+
            "--! :"+
            "Quit`^q"
      )
      AddMenu(
         " Action "
            "Pause Game`^p:"+
            "Inventory`^I:"+
            "Retype`#3:"+
            "--! :"+
            "Colors`^c"
      )
      AddMenu(
         " Speed "
            "Change...`^s:"+
            "--!:"+
            "Faster`+:"+
            "Normal`=:"+
            "Slower`-"
      )
      (if(DoSound(sndSET_SOUND))
         AddMenu(
            " Sound "
               "Volume...`^v:"+
               "Turn Off`#2=1"
         )
      )(else
         AddMenu(
            " Sound "
               "Volume...`^v:"+
               "Turn On`#2=1"
         )
      )
      (if(< Graph(grGET_COLOURS) 9)
         SetMenu(MENU_COLOURS 32 0)
      )(else
         SetMenu(MENU_COLOURS smMENU_SAID '/color')
      )
      SetMenu(MENU_SAVE      smMENU_SAID 'save[/game]')
      SetMenu(MENU_RESTORE   smMENU_SAID 'restore[/game]')
      SetMenu(MENU_RESTART   smMENU_SAID 'restart[/game]')
      SetMenu(MENU_QUIT      smMENU_SAID 'done[/game]')
      SetMenu(MENU_PAUSE      smMENU_SAID 'delay[/game]')
      SetMenu(MENU_INVENTORY   smMENU_SAID 'all')
   )
   (method (handleEvent pEvent)
      (var menuItem, hGauge, newSpeed, newVolume, wndCol, wndBack, hPause)
      = menuItem (super:handleEvent(pEvent))
      (switch(menuItem)
         (case MENU_ABOUT
            Print(
               "       Template Game\n"+
               " By Brian Provinciano"
               #title "About"
            )
         )
         (case MENU_HELP
            Print(
               "<Put your how to play stuff here>"
               #title "How To Play"
            )
         )
         (case MENU_LIST
            Print(
               "LOOK  OPEN  CLOSE  SPEAK  TALK"
               #title "Command list"
            )
         )
         (case MENU_RESTART
            (if(Print(
                 "Are you serious? You really want to start all the way back at the beginning again?"
                 #title "Restart"
                 #font gDefaultFont
                 #button "Restart" 1
                 #button " Oops " 0
               )
               )
               (send gGame:restart())                  
            )
         )
         (case MENU_RESTORE  
            (send gGame:restore())
         )

... to be continued

Offline robingravel

Re:menubar.sc
« Reply #2 on: September 16, 2003, 06:11:55 PM »
Quote

         (case MENU_SAVE                  
            (send gGame:save())
         )
         (case MENU_QUIT          
            (if(Print(
                 "Do you really want to quit?"
                 #title "Quit"
                 #font gDefaultFont
                 #button " Quit " 1
                 #button " Oops " 0
               )
               )
                  = gQuitGame TRUE              
            )
         )
         (case MENU_PAUSE
            = hPause (Sound:pause())
             Print("Game Paused")
             (Sound:pause(hPause))
         )
         (case MENU_INVENTORY
            (if(PrintCantDoThat($400))
               (send gInv:showSelf(gEgo))
             )
         )
         (case MENU_RETYPE
            (send pEvent:
               claimed(FALSE)
               type(evKEYBOARD)
               message( (User:echo) )
            )
         )
         (case MENU_COLOURS
            = wndCol 16
            (while(>u wndCol 15 and <> wndCol -1)
               = wndCol GetNumber("New Text Color: (0-15)")
            )
            (if(<> wndCol -1)
               = wndBack 16
               (while(<> wndBack -1 and >u wndBack 15 or == wndCol wndBack)
                  = wndBack GetNumber("New Background Color: (0-15)")
               )
               (if(<> wndBack -1)
                  = gWndColor wndCol
                  = gWndBack wndBack
                  (send gTheWindow:
                     color(gWndColor)
                     back(gWndBack)
                  )
               )
            )
         )
         (case MENU_CHANGESPEED
            = hGauge (Gauge:new())
            = newSpeed
               (send hGauge:
                  text("Game Speed")
                  description("Use the mouse or the left and right arrow keys to select the game speed.")
                  higher("Faster")
                  lower("Slower")
                  normal(NORMAL_SPEED)
                  doit(- 15 gSpeed)
               )
            (send gGame:setSpeed(- 15 newSpeed))
            DisposeScript(GAUGE_SCRIPT)
         )
         (case MENU_FASTERSPEED
            (if(gSpeed)
               (send gGame:setSpeed(--gSpeed))
            )
         )
         (case MENU_NORMALSPEED
            (if(gSpeed)
               (send gGame:setSpeed(12))
            )
         )
         (case MENU_SLOWERSPEED
            (if(< gSpeed 15)
               (send gGame:setSpeed(++gSpeed))
            )
         )
         (case MENU_VOLUME
            = hGauge (Gauge:new())
            = newVolume
               (send hGauge:
                  text("Sound Volume")
                  description("Use the mouse or the left and right arrow keys to adjust the volume.")
                  higher("Louder")
                  lower("Softer")
                  normal(15)
                  doit(DoSound(sndVOLUME newVolume))
               )
            DoSound(sndVOLUME newVolume)
            DisposeScript(GAUGE_SCRIPT)
         )
         (case MENU_TOGGLESOUND
            ToggleSound()
         )
      )
   )
)
/******************************************************************************/
(procedure public (ToggleSound)
   (var SOUND_OFF)
   = SOUND_OFF DoSound(sndSET_SOUND)
   = SOUND_OFF DoSound( sndSET_SOUND not(SOUND_OFF) )
   (if(SOUND_OFF)
      SetMenu(MENU_TOGGLESOUND smMENU_TEXT "Turn On")
   )(else
      SetMenu(MENU_TOGGLESOUND smMENU_TEXT "Turn Off")
   )
)

I have no problem when compiling but nothing happens in the game by pressing F6 or it doesn't show in the menu.

What's wrong?


Robin Gravel

PS: sorry but I got 'you're message is too long
« Last Edit: September 16, 2003, 06:15:20 PM by Robin_Gravel »

Offline Chris Cromer

Re:menubar.sc
« Reply #3 on: September 16, 2003, 07:18:09 PM »
Change this:
Code: [Select]
     AddMenu(
         "  "
            "About Template`^a:"+
            "Help`#1"
            "Command list`#6"
      )

To this:
Code: [Select]
     AddMenu(
         "  "
            "About Template`^a:"+
            "Help`#1:"+
            "Command list`#6"
      )

You forgot the + after the " which is why it doesn't show anything or do anything.
« Last Edit: September 16, 2003, 08:58:00 PM by Chris Cromer »
Chris Cromer

It's all fun and games until someone get's hurt then it's just fun. ;)

Offline robingravel

Re:menubar.sc
« Reply #4 on: September 16, 2003, 08:04:56 PM »
Thanks Chris

But it still not works.


Robin Gravel

Offline Chris Cromer

Re:menubar.sc
« Reply #5 on: September 16, 2003, 08:58:37 PM »
I modified my code, didn't notice a missing : before the " until just now.
Chris Cromer

It's all fun and games until someone get's hurt then it's just fun. ;)

Offline robingravel

Re:menubar.sc
« Reply #6 on: September 16, 2003, 11:01:24 PM »
Thanks again Chris

I made another mistake in my code. I fixed it.


Here the correct code:
Quote
AddMenu(
        "  "
            "About Template`^a:"+
            "Help`#1:"
            "Command list`#6:"
      )
My game works.


Robin Gravel


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.045 seconds with 21 queries.