Computer Science Canada

menus/exit help

Author:  Michael [ Thu Sep 07, 2006 8:52 pm ]
Post subject:  menus/exit help

hey people.

My first turing assignment is to answer 5 questions..
all questions are pretty easy but I have a problem doing a menu to access
these questions.

This is what I got so far:

code:


View.Set ("graphics:400;400")
setscreen ("offscreenonly")
var x, y, button : int
loop
    % Background
    Draw.FillBox (maxx - 400, maxy - 400, maxx, maxy, blue)
    % Color settings
    colorback (blue)
    color (white)
    % Mouse Location
    Mouse.Where (x, y, button)
    Text.Locate (1, 1)
    if button = 0 then
        put x : 4, "  ", y : 4, "  button up"
    else
        put x : 4, "  ", y : 4, "  button down"
    end if

    % Font Settings
    var font4 : int
    font4 := Font.New ("Arial:17:bold,italic")
    assert font4 > 0

    % Main Program
    put "                     ICS 1"
    put "                Michael Litvak"
    put "     --------------------------------------"
    Font.Draw ("Question 1", 125, 280, font4, white)
    Font.Draw ("Question 2", 125, 240, font4, white)
    Font.Draw ("Question 3", 125, 200, font4, white)
    Font.Draw ("Question 4", 125, 160, font4, white)
    Font.Draw ("Question 5", 125, 120, font4, white)

    % Boxes around Menu
    drawbox (123, 278, 245, 297, white)
    drawbox (123, 237, 245, 257, white)
    drawbox (123, 197, 245, 216, white)
    drawbox (123, 158, 245, 176, white)
    drawbox (123, 118, 245, 137, white)

    % Mouse over IFs
    if x > 127 and x < 240 and y > 278 and y < 297 then
        Font.Draw ("Question 1", 125, 280, font4, brightgreen)
        drawbox (123, 278, 245, 297, brightgreen)

    elsif x > 127 and x < 240 and y > 240 and y < 260 then
        Font.Draw ("Question 2", 125, 240, font4, brightgreen)
        drawbox (123, 237, 245, 257, brightgreen)

    elsif x > 127 and x < 240 and y > 200 and y < 214 then
        Font.Draw ("Question 3", 125, 200, font4, brightgreen)
        drawbox (123, 197, 245, 216, brightgreen)

    elsif x > 127 and x < 240 and y > 160 and y < 172 then
        Font.Draw ("Question 4", 125, 160, font4, brightgreen)
        drawbox (123, 158, 245, 176, brightgreen)

    elsif x > 127 and x < 240 and y > 160 and y < 172 then
        Font.Draw ("Question 4", 125, 160, font4, brightgreen)
        drawbox (123, 158, 245, 176, brightgreen)

    elsif x > 127 and x < 240 and y > 120 and y < 132 then
        Font.Draw ("Question 5", 125, 120, font4, brightgreen)
        drawbox (123, 118, 245, 137, brightgreen)
    end if


    %Mouse click IFs

    if x > 127 and x < 240 and y > 278 and y < 297 and button = 1 then
        var number : int := -15
        %question1
        cls
        loop
            put number, "," ..
            number := number + 5

            if number > 100 then
                return
            end if

        end loop

    end if

    delay (1)
    View.Update


end loop






Only question 1 works so far... the purpose of question 1 is to display numbers from -15 to 100 using a loop.. easy..
When you click "question 1" on the menu, it brings you to question 1 page and stops. I want it to go to that page for 3-4 seconds then exit that loop and come back to the menu? how can I do that? I've tried the exit command but it exits as soon as i press the menu, delay doesn't help.

Thanks.

Author:  TokenHerbz [ Thu Sep 07, 2006 9:42 pm ]
Post subject: 

Hello, Im glad to see that you've at least attempted this question, so i am willing to assist you.

I'm not going to show you anything fancy, out of your knowledge yet, But here is a way to fix your problem.

code:

if x > 127 and x < 240 and y > 278 and y < 297 and button = 1 then
        var number : int := -15
        %question1
        cls
        loop
            put number, "," ..
            number := number + 5

          %  if number > 100 then
            %    return
           % end if
            exit when number > 100
        end loop
        View.Update
        delay(600)
    end if


What happends is: When we enter into the questions loop, we get all the info put out, and we "View.Update" it to see what was put. This delay you can modify, what it does is stall the program for a time (which is the number) so, we draw the output, and stall the program for a few secs, to let someone read this output, then exit back to your menu.

Hope i helped, and good luck on your other questions.

Author:  Michael [ Thu Sep 07, 2006 10:16 pm ]
Post subject: 

awesome exactly what i needed Very Happy

problem solved.. thanks!


: