Computer Science Canada

mouseover loop problem

Author:  beedub [ Thu May 06, 2004 10:40 am ]
Post subject:  mouseover loop problem

i tried making a menu program with no GUI, im having some trouble with using 'get' statements. When the button is pressed i cant use a get statement without the program stopping and having some sort of error. heres my program. ty

code:

View.Set ("offscreenonly")
%menu.t
colorback (23)
color (30)
var font1, font2, font3, font4, line : int
font1 := Font.New ("courier:10")
font2 := Font.New ("courier:10:bold")

%function mouseover
var mousex, mousey, mouseb, mousex1, mousey1, mouseb1, mousex2, mousey2, mouseb2, mousex3, mousey3, mouseb3 : int
function mouseover (x1, y1, x2, y2 : int) : boolean
    var x, y, b : int
    mousewhere (x, y, b)
    if (x >= x1 and x <= x2) or (x >= x2 and x <= x1) then
        if (y >= y1 and y <= y2) or (y >= y2 and y <= y1) then
            result true
        end if
    end if
    result false
end mouseover

drawfillbox (0, 0, 640, 400, 23)


loop
    if mouseover (500, 300, 600, 320) then
        drawfillbox (500, 300, 600, 320, 23)
        drawbox (500, 300, 600, 320, black)
        Font.Draw ("Play game", 505, 308, font1, black)
    else
        drawfillbox (500, 300, 600, 320, 27)
        drawbox (500, 300, 600, 320, black)
        Font.Draw ("Play game", 505, 308, font1, black)
    end if
    if mouseover (500, 295, 600, 275) then
        drawfillbox (500, 295, 600, 275, 24)
        drawbox (500, 295, 600, 275, black)
        Font.Draw ("RULES", 505, 280, font1, black)
    else
        drawfillbox (500, 295, 600, 275, 27)
        drawbox (500, 295, 600, 275, black)
        Font.Draw ("RULES", 505, 280, font1, black)
    end if
    if mouseover (500, 270, 600, 250) then

        drawfillbox (500, 270, 600, 250, 25)
        drawbox (500, 270, 600, 250, black)
        Font.Draw ("High Scores", 505, 255, font1, black)
    else
        drawfillbox (500, 270, 600, 250, 27)
        drawbox (500, 270, 600, 250, black)
        Font.Draw ("High Scores", 505, 255, font1, black)
    end if
    if mouseover (500, 245, 600, 225) then

        drawfillbox (500, 245, 600, 225, 26)
        drawbox (500, 245, 600, 225, black)
        Font.Draw ("EXIT", 505, 230, font1, black)
    else
        drawfillbox (500, 245, 600, 225, 27)
        drawbox (500, 245, 600, 225, black)
        Font.Draw ("EXIT", 505, 230, font1, black)
    end if

    var button : int
    button := 0
    var x2, y3 : int
    x2 := 450
    y3 := 310

    Mouse.Where (x2, y3, button)

    if whatdotcolor (x2, y3) = 23 and button = 1 then
        cls
        drawfillbox (0, 0, 640, 400, 23)
var ans4: string       
put "play"
get ans4
   
    else
    end if

    var x3, y4 : int
    x3 := 450
    y4 := 285

    Mouse.Where (x3, y4, button)

    if whatdotcolor (x3, y4) = 24 and button = 1 then
        cls
        drawfillbox (0, 0, 640, 400, 23)
        put "                         RULES"
        put "                         ------"
        put ""
        put "   The name of the game is blackjack."
        put "   Closest to 21 without going over, wins."
        put "   Aces are worth 1 and 11 pending if you're going over 21"
        put "   Face Cards are worth 10"
        put "   In Case of tie the dealer wins."
        put "   If player is over 21, they immediatly lose."
    else
    end if
    var x4, y5 : int
    x4 := 450
    y5 := 265

    Mouse.Where (x4, y5, button)

    if whatdotcolor (x4, y5) = 25 and button = 1 then
        cls
        drawfillbox (0, 0, 640, 400, 23)
        put "                         HIGH SCORES"
        put "                         -----------"
        put ""
        put "    1. Benjamin evans Walker"
        put "    2. Beedub"
        put "    3. BlanG"
    else
    end if
    var x5, y6 : int
    x5 := 450
    y6 := 245

    Mouse.Where (x5, y6, button)

    if whatdotcolor (x5, y6) = 26 and button = 1 then
        cls
        drawfillbox (0, 0, 640, 400, 23)
        put "exit"
    else
    end if
    View.Update
    delay (5)
end loop

Author:  Dan [ Thu May 06, 2004 4:05 pm ]
Post subject: 

to do input that is non-blocking uses hasch:

if hasch then
getch(c)
end if

this will only input a char if there is one to input and will not stop the progame.

there is also some other input methods that are non-blocking but they only work with turing 4.x, more can be found out about them in the turing refercen.

Author:  beedub [ Thu May 06, 2004 5:18 pm ]
Post subject: 

how would the code go. for example in the "play" area?

Author:  beedub [ Sun May 09, 2004 1:28 pm ]
Post subject: 

any1?

Author:  Dan [ Sun May 09, 2004 3:37 pm ]
Post subject: 

i am a litte confiused about what u are trying to inpiut. What is it that u whont to input in the var ans4?

Author:  beedub [ Sun May 09, 2004 5:06 pm ]
Post subject: 

yea, well, im going to need to input numerous of other variables its just, im testing with that 1.

Author:  Dan [ Sun May 09, 2004 11:10 pm ]
Post subject: 

well it makes a diffrence on how to input it. if it is just one char long then u can easly uses the hasch/getch method to get a letter, number or keystrok. But if u whont to get a hole word of a number that is >=10 then u will have to make a method of inputing more then one char using getch/hasch.

Author:  beedub [ Mon May 10, 2004 10:47 am ]
Post subject: 

well, lets say its at a max of 3 chars long


: