Computer Science Canada

Returning To Menu From Procedure

Author:  pkchris [ Wed Dec 14, 2005 6:12 pm ]
Post subject:  Returning To Menu From Procedure

I'm trying to return to my main menu from a procedure. Could someone please explain to me the best method? My main menu is just a few buttons in the mainline of my program which target the procedures I want to exit.

Author:  Paul [ Wed Dec 14, 2005 6:52 pm ]
Post subject: 

Could you explain more about what your procedure does, how its coded etc? So we can help you better, a bit of code won't hurt either.
As for now it seems [url=http://www.compsci.ca/v2/viewtopic.php?t=370"]This tutorial[/url] could help you.

Author:  pkchris [ Wed Dec 14, 2005 10:33 pm ]
Post subject: 

Here's my program so far... It's supposed to simulate a slot machine but it isn't done yet.

Author:  pkchris [ Thu Dec 15, 2005 11:34 am ]
Post subject: 

Oops I don't have any comments yet. Here is the basic code that I need help with though. You can still get all of my code from the above attachment.

code:

import GUI
var winID := Window.Open ("graphics:140;100")
procedure Game %Runs my slots from three processes not included here.
    setscreen ("graphics:650;400,nobuttonbar")
    locate (20, 16)
    put "Push '1' then '2' then '3' to stop the reels."
    fork Slot1
    fork Slot2
    fork Slot3
end Game
var button1 : int := GUI.CreateButton (10, 70, 15, "Start Game", Game)%Game button
var button3 : int := GUI.CreateButton (10, 10, 15, "Quit", GUI.Quit)%Closes Window to Quit
loop
    exit when GUI.ProcessEvent
end loop
Window.Close (winID)

This game button runs the procedure "Game." After "Game" is done I want to return to my main menu which is the buttons

Author:  Taur [ Fri Dec 16, 2005 4:23 pm ]
Post subject: 

are slots 1, 2 and 3 processes?

Author:  pkchris [ Fri Dec 16, 2005 8:20 pm ]
Post subject: 

Yes, so they all activate at the same time... Can you help me? Razz

Author:  Taur [ Fri Dec 16, 2005 8:59 pm ]
Post subject: 

well I think it might be about that whole processes in turing are bad thing, thier screwed up, I'm not sure how but it's recommended that you don't use them.

Author:  pavol [ Fri Dec 16, 2005 9:06 pm ]
Post subject: 

try putting your code in a loop that way it will run the main menu again. thats the problem with procedures, they need to be declared before they can be called but what if they rely on each other. theres the problem. i had a problem like this myself once ... and then i gave up. try the loop thing, it might get you somewhere

Author:  pkchris [ Sat Dec 17, 2005 12:11 am ]
Post subject: 

I have been able to do this properly using loops with a case statement main menu, but I'm using buttons and procedures right now. I can't put procedures in into a loop. Also processes are fine to use just like any other coding, except they can interfere with other parts of your programming. I haven't ran into any trouble yet...

Author:  pkchris [ Mon Dec 19, 2005 6:15 pm ]
Post subject: 

If this is impossible, let me know!!

Author:  Albrecd [ Mon Dec 19, 2005 6:25 pm ]
Post subject: 

You could put the Menue in a procedure instead of the mainline of the program and then call it in the mainline as well as the place that you are trying to make it work now.

Author:  pkchris [ Mon Dec 19, 2005 8:52 pm ]
Post subject: 

That was the first thing I tried. I can't do that because my main menu uses buttons which target procedures. So if I did do that I would get the error that I need to define the procedures that my buttons use first. Or if I put my main menu after I create those procedures, it will say I have to declare my main menu first since my other procedures target it.

In simple terms I can't.

Author:  Albrecd [ Mon Dec 19, 2005 9:03 pm ]
Post subject: 

You could put the whole program in a loop so that when it finishes, it loops back to the menue.

Author:  Martin [ Mon Dec 19, 2005 9:35 pm ]
Post subject: 

code:

var MENU : int := 1
var GAME : int := 2
... etc.
var mode : int := 1
loop
    if (mode = MENU)
        ... do menu stuff
        if (user clicks play button)
            mode := GAME
        end if
     elsif (mode = GAME)
        ... do game stuff
     elsif (mode = ...)
        ...
     end if
end loop

Author:  pkchris [ Wed Dec 21, 2005 11:38 am ]
Post subject: 

My main menu has a quit button in it so it becomes stuck.

Author:  pkchris [ Wed Dec 21, 2005 11:42 am ]
Post subject: 

Here's my new coding that isn't working:

code:

import GUI
var firstslot : string
var secondslot : string
var thirdslot : string
var streamin, streamout : int
var highscore : string
var cnt : int
var chars : array char of boolean
var font1, font2, font3, font4, font5, font6, font7, font8, font9, fony10, font11, font12, font13, fonr14, font15 : int
var mode : int := 1
var switch : string := ""
process DoMusic
    loop
        Music.PlayFile ("Star_Light_Zone2.mid")
    end loop
end DoMusic
fork DoMusic
process Slot1
    loop
        for counter : 1 .. 4
            if counter = 1 then
                delay (20)
                Draw.FillBox (50, 150, 200, 300, blue)
                Draw.FillStar (50, 150, 200, 300, white)
                firstslot := "boxstar"
            elsif counter = 2 then
                delay (20)
                Draw.FillBox (50, 150, 200, 300, red)
                Draw.FillOval (125, 225, 75, 75, white)
                firstslot := "boxcircle"
            elsif counter = 3 then
                delay (20)
                Draw.FillBox (50, 150, 200, 300, green)
                Draw.FillMapleLeaf (50, 150, 200, 300, white)
                firstslot := "boxmapleleaf"
            elsif counter = 4 then
                delay (20)
                Draw.FillBox (50, 150, 200, 300, purple)
                Draw.FillArc (125, 200, 75, 75, 0, 180, white)
                firstslot := "boxarc"
            end if
            Input.KeyDown (chars)
            exit when chars ('1')
        end for
        exit when chars ('1')
    end loop
end Slot1
process Slot2
    loop
        for counter : 1 .. 4
            if counter = 1 then
                delay (20)
                Draw.FillBox (250, 150, 400, 300, blue)
                Draw.FillStar (250, 150, 400, 300, white)
                secondslot := "boxstar"
            elsif counter = 2 then
                delay (20)
                Draw.FillBox (250, 150, 400, 300, red)
                Draw.FillOval (325, 225, 75, 75, white)
                secondslot := "boxcircle"
            elsif counter = 3 then
                delay (20)
                Draw.FillBox (250, 150, 400, 300, green)
                Draw.FillMapleLeaf (250, 150, 400, 300, white)
                secondslot := "boxmapleleaf"
            elsif counter = 4 then
                delay (20)
                Draw.FillBox (250, 150, 400, 300, purple)
                Draw.FillArc (325, 200, 75, 75, 0, 180, white)
                secondslot := "boxarc"
            end if
            Input.KeyDown (chars)
            exit when chars ('2')
        end for
        exit when chars ('2')
    end loop
end Slot2
process Slot3
    loop
        for counter : 1 .. 4
            if counter = 1 then
                delay (20)
                Draw.FillBox (450, 150, 600, 300, blue)
                Draw.FillStar (450, 150, 600, 300, white)
                thirdslot := "boxstar"
            elsif counter = 2 then
                delay (20)
                Draw.FillBox (450, 150, 600, 300, red)
                Draw.FillOval (525, 225, 75, 75, white)
                thirdslot := "boxcircle"
            elsif counter = 3 then
                delay (20)
                Draw.FillBox (450, 150, 600, 300, green)
                Draw.FillMapleLeaf (450, 150, 600, 300, white)
                thirdslot := "boxmapleleaf"
            elsif counter = 4 then
                delay (20)
                Draw.FillBox (450, 150, 600, 300, purple)
                Draw.FillArc (525, 200, 75, 75, 0, 180, white)
                thirdslot := "boxarc"
            end if
            Input.KeyDown (chars)
            exit when chars ('3')
        end for
        exit when chars ('3')
    end loop
end Slot3
procedure Gamestart
    mode := 2
end Gamestart
procedure Highstart
    mode := 3
end Highstart
var winID := Window.Open ("graphics:750;500")
setscreen ("graphics")
font1 := Font.New ("Arial:35:bold")
assert font1 > 0
font2 := Font.New ("Arial:12:bold")
assert font2 > 0
font3 := Font.New ("Arial:30:bold")
assert font3 > 0
Font.Draw ("Slot Machine Simulator", 50, 355, font1, 32)
Font.Draw ("Instructions:", 1, 330, font2, 1)
Font.Draw ("First you input the money you want to bet.", 1, 310, font2, 1)
Font.Draw ("You get 30 coins to start off with.", 1, 290, font2, 1)
Font.Draw ("Then you press 1, then 2, then 3, to stop the reels.", 1, 270, font2, 1)
Font.Draw ("Try to line up the pictures to earn points.", 1, 250, font2, 1)

Font.Draw ("The following combos are winners:", 1, 210, font2, 1)
Font.Draw ("3 Semi Circles - 4 extra tokens", 1, 190, font2, 1)
Font.Draw ("3 Circles - 8 extra tokens", 1, 170, font2, 1)
Font.Draw ("2 Semi Circles and 1 Circle - 12 extra coins", 1, 150, font2, 1)
Font.Draw ("2 Circles and 1 Semi Circle - 15 extra coins", 1, 130, font2, 1)
Font.Draw ("2 Maple Leafs and 1 Star - 20 extra coins", 1, 110, font2, 1)
Font.Draw ("3 Maple Leafs - 24 extra coins", 1, 90, font2, 1)
Font.Draw ("2 Stars and 1 Maple Leafs - 30 extra coins", 1, 70, font2, 1)
Font.Draw ("3 Stars - 40 extra tokens", 1, 50, font2, 1)
setscreen ("noecho")
setscreen ("nocursor")
loop
    Font.Draw ("Please Hit Enter to Continue", 210, 10, font2, 1)
    Input.KeyDown (chars)
    exit when chars (KEY_ENTER)
end loop
setscreen ("echo")
setscreen ("cursor")
Window.Close (winID)
loop
    if mode = 1 then
        loop
            var winID2 := Window.Open ("graphics:340;300")
            Font.Draw ("Slot Machine", 45, 250, font3, 2)
            Font.Draw ("Simulator", 75, 220, font3, 2)
            var button1 : int := GUI.CreateButton (110, 70, 15, "Start New Game", Gamestart)
            var button2 : int := GUI.CreateButton (110, 40, 15, "View Highscores", Highstart)
            var button3 : int := GUI.CreateButton (110, 10, 15, "Quit", GUI.Quit)
            if mode = 2 or mode = 3 then
                exit
            end if
            loop
                exit when GUI.ProcessEvent
            end loop
            Window.Close (winID2)
        end loop
    elsif mode = 2 then
        setscreen ("graphics:650;400,nobuttonbar")
        locate (20, 16)
        put "Push '1' then '2' then '3' to stop the reels."
        fork Slot1
        fork Slot2
        fork Slot3
    elsif mode = 3 then
        loop
            locate (1, 1)
            put "Name:     Score:"
            cnt := 1
            setscreen ("graphics:650;400,nobuttonbar")
            open : streamin, "HIGHSCORES.txt", get
            assert streamin > 0
            loop
                exit when eof (streamin)
                get : streamin, highscore : *
                cnt := cnt + 1
                locate (cnt, 1)
                put highscore
            end loop
            close : streamin
            locate (20, 16)
            put "Push 'x' to clear highscores and 'enter' to go back."
            Input.KeyDown (chars)
            if chars ('x') then
                cls
                open : streamout, "HIGHSCORES.txt", put
                assert streamout > 0
                put : streamout, ""
                close : streamout
            end if
            exit when chars (KEY_ENTER)
        end loop
    end if
end loop

Author:  do_pete [ Wed Dec 21, 2005 11:52 am ]
Post subject: 

You should really comment your code because it makes it easier for everyone to understand


: