Computer Science Canada

Fixing a button!

Author:  chibitenshi_03 [ Mon Apr 12, 2004 1:59 pm ]
Post subject:  Fixing a button!

I'm trying to make a button within a window. The window allows the user to choose a song and the button is for the user to exit the windosw without choosing a song.

var number, windID, font5 : int
var x, y, b : int
var name : string
windID := Window.Open ("position:top;center,graphics:400,300")
font5 := Font.New ("ariel:14:bold")
assert font5 > 0
Font.Draw ("Exit", 260, 40, font5, 1)
Font.Free (font5)
drawbox (250, 35, 310, 60, 1)
Mouse.ButtonChoose ("singlebutton")
Mouse.Where (x, y, b)
if x >= 250 and x <= 310 and y >= 35 and y <= 60 and b = 1 then
Window.Close(windID)
end if
put "Please choose a song:"
put "1. Under the Sea"
put "2. A Whole New World"
put "3. Hakuna Matata"
put "4. Circle of Life"
put "5. Be Our Guest"
put "6. Color of the Wind"
put "7. Can You Fell the Love Tonight"
put "8. Part of Your World"
put " "
put "Enter the number: " ..
get number

Window.Close (windID)
I don't know why it doesn't work. Please help fix it.

Author:  Paul [ Mon Apr 12, 2004 2:44 pm ]
Post subject: 

well the problem is, it goes thru the if statement before there is a click.

Author:  apomb [ Mon Apr 12, 2004 2:48 pm ]
Post subject: 

Well, it doesn't work because it is waiting for the input from the keyboard, not the mouse at the moment, you need some sort of loop , where it is constanly checking for both mouse and keyboard inputs. Hope that helps.

Here's the code i figured out
code:

var number, windID, font5 : int
var x, y, b : int
var name : string
windID := Window.Open ("position:top;center,graphics:max,max")
font5 := Font.New ("ariel:14:bold")
assert font5 > 0
loop
    put "Please choose a song:"
    put "1. Under the Sea"
    put "2. A Whole New World"
    put "3. Hakuna Matata"
    put "4. Circle of Life"
    put "5. Be Our Guest"
    put "6. Color of the Wind"
    put "7. Can You Fell the Love Tonight"
    put "8. Part of Your World"
    put " "
    put "Enter the number: " ..
    Font.Draw ("Exit", 260, 40, font5, red)
    drawbox (250, 35, 310, 60, black)
    loop
        if hasch then
            get number
        end if
        mousewhere (x, y, b)
        if x >= 250 and x <= 310 and y >= 35 and y <= 60 and b = 1 then
            Window.Close (windID)
        end if
    end loop
end loop

Author:  Paul [ Mon Apr 12, 2004 2:53 pm ]
Post subject: 

The window doesn't close properly, do this:
code:

loop
        if hasch then
            get number
        end if
        mousewhere (x, y, b)
        if x >= 250 and x <= 310 and y >= 35 and y <= 60 and b = 1 then
             exit
        end if
    end loop
    if b=1 then
    exit
    end if
end loop
Window.Close (windID)

Author:  apomb [ Mon Apr 12, 2004 2:56 pm ]
Post subject: 

ya i just figured that out , the code i got was to forget about the loop around the whole thing, that way it wouldn't open another window, waiting for input. btw, paul that code doesn't work either

code:
var number, windID, font5 : int
var x, y, b : int
var name : string
windID := Window.Open ("position:top;center,graphics:300,400")
font5 := Font.New ("ariel:14:bold")
assert font5 > 0
put "Please choose a song:"
put "1. Under the Sea"
put "2. A Whole New World"
put "3. Hakuna Matata"
put "4. Circle of Life"
put "5. Be Our Guest"
put "6. Color of the Wind"
put "7. Can You Fell the Love Tonight"
put "8. Part of Your World"
put " "
put "Enter the number: " ..
Font.Draw ("Exit", 260, 40, font5, red)
drawbox (250, 35, 310, 60, black)
loop
    if hasch then
        get number
    end if
    mousewhere (x, y, b)
    if x >= 250 and x <= 310 and y >= 35 and y <= 60 and b = 1 then
        Window.Close (windID)
        exit
    end if
end loop

there, it works now

Author:  chibitenshi_03 [ Mon Apr 12, 2004 3:33 pm ]
Post subject: 

thanks for all the help!

Author:  chibitenshi_03 [ Mon Apr 12, 2004 3:44 pm ]
Post subject: 

there's another problem now....the music won't play?

Author:  gamer [ Mon Apr 12, 2004 3:47 pm ]
Post subject: 

wut music ar u talkin about?
background music?

Author:  gamer [ Mon Apr 12, 2004 3:51 pm ]
Post subject: 

if u are talkin bout the songs, then i guess u can do case structure

code:

case number of
label "1":
Music.PlayFile ("Under the Sea.wav")
label "2":
Music.PlayFile ("A Whole New World")
.
.
.
.
.
end case


or u can use if statement, but in this situation case is better


: