Computer Science Canada Button and Animation working at same time |
Author: | mrfungu [ Sun Dec 02, 2007 1:26 am ] |
Post subject: | Button and Animation working at same time |
Hi. Im having a lot of trouble getting an animation and a button to work at the same time. I decided to put the animation in a process and fork it. My first problem is now that the animation is in a fork, it work stop. I've been told to create a seperate boolean variable that will exit the loop when the statement becomes true. So far, this has not worked for me. Furthermore, if i put the animation into a proc, the button will now show or activate until the animation is done. My first question is: Is there a command or more effective way to end a fork? and if so. what is it? My second question is: Is there an error in the order of my code because it seems to be skipping the declaration of the variable being true. Sorry for asking so many questions! ![]() here is the program, it is also attached import GUI var instructBtn, menuBtn : int := 0 var mainWin := Window.Open ("position:180;50, graphics:500;500") var flag : boolean := false % Main Menu proc mainMenu %Game Menu flag := true cls put "Menu" GUI.Hide (menuBtn) GUI.Show (instructBtn) GUI.Refresh end mainMenu % Introduction proc intro cls GUI.Hide (instructBtn) GUI.Show (menuBtn) var font6 : int font6 := Font.New ("arial bold:20") assert font6 > 0 Font.Draw ("TEMPERATURE CONVERTER", 35, 380, font6, black) Font.Free (font6) View.Update GUI.Refresh end intro process anim for y : 0 .. 190 for w : 0 .. 220 by 15 loop drawline (356, 105 + y, 389, 105 + y, 12) drawline (356, 105 + w, 389, 105 + w, 7) delay (3) exit when flag = true end loop end for end for end anim % Instructions proc instructions cls var font1 : int fork anim font1 := Font.New ("arial :30") Font.Draw ("I", 85, 380, font1, black) var font3 : int font3 := Font.New ("arial bold:20") Font.Draw ("NSTRUCTIONS", 95, 380, font3, black) var font4 : int font4 := Font.New ("arial:13") Font.Draw ("This program will convert Fahrenheit to ", 20, 350, font4, black) Font.Draw ("Celcius. The first step is to enter the", 20, 330, font4, black) Font.Draw ("temperature in Fahrenhiet using the buttons.", 20, 310, font4, black) Font.Draw ("The degrees in Fahrenhiet can not be larger.", 20, 290, font4, black) Font.Draw ("than ten digits. ", 20, 270, font4, black) Font.Free (font4) drawfilloval (372, 70, 40, 40, 12) for i : 0 .. 5 drawline (350 + i, 105, 350 + i, 350, 7) drawline (390 + i, 105, 390 + i, 350, 7) drawarc (372, 70, 40 + i, 40 + i, 115, 65, 7) end for for z : 0 .. 220 by 15 drawline (356, 105 + z, 389, 105 + z, 15) end for var font2 : int font2 := Font.New ("arial bold:13") assert font2 > 0 Font.Draw ("0", 400, 105, font2, black) Font.Draw ("5", 400, 130, font2, black) Font.Draw ("10", 400, 160, font2, black) Font.Draw ("15", 400, 190, font2, black) Font.Draw ("20", 400, 220, font2, black) Font.Draw ("25", 400, 250, font2, black) Font.Draw ("30", 400, 280, font2, black) Font.Draw ("35", 400, 310, font2, black) Font.Draw ("C", 407, 340, font2, black) Font.Free (font2) var font5 : int font5 := Font.New ("arial bold:10") Font.Draw ("o", 399, 345, font5, black) GUI.Show (menuBtn) View.Update end instructions instructBtn := GUI.CreateButton (185, 200, 100, "Instructions", instructions) menuBtn := GUI.CreateButton (185, 18, 100, "Menu", mainMenu) % Main Program intro loop exit when GUI.ProcessEvent end loop |
Author: | Tony [ Sun Dec 02, 2007 2:15 am ] | ||
Post subject: | RE:Button and Animation working at same time | ||
Please use [ code ] or [ syntax ] tags. You're on the right track, and the exit condition is not skipped. It's just that
your inner loop that you are exiting is inside two other for loops. You'd have to exit this another 200 times or so for the process to finish. |
Author: | mrfungu [ Sun Dec 02, 2007 2:56 pm ] |
Post subject: | RE:Button and Animation working at same time |
So in order to fix this problem i will need to move the loop command outside of the for loop? |
Author: | Tony [ Sun Dec 02, 2007 4:10 pm ] |
Post subject: | RE:Button and Animation working at same time |
why is there a loop in the first place? |
Author: | mrfungu [ Sun Dec 02, 2007 8:26 pm ] |
Post subject: | RE:Button and Animation working at same time |
the purpose of the loop is so that it know when to stop. so that the fork knows to exit when the variable comes true. ive tried an if statement saying [code] if flag = false then anim elsif flag = true then mainMenu else end if but the animation did not RUN. >.> |
Author: | Tony [ Sun Dec 02, 2007 8:31 pm ] |
Post subject: | RE:Button and Animation working at same time |
exit exits the loop. Fork ends only when it gets to the end, same as any other function or procedure. You need to figure out a way to structure your code in such a way that you could quickly get to the end of the process when needed. |
Author: | mrfungu [ Sun Dec 02, 2007 8:43 pm ] |
Post subject: | RE:Button and Animation working at same time |
oo. i understand! thanks tony ![]() |
Author: | Tony [ Sun Dec 02, 2007 9:02 pm ] |
Post subject: | RE:Button and Animation working at same time |
if statements and loops are a common way to control logic flow. Return statements are excellent too, though Turing might limit those just to functions -- I'm not sure. You are very close to a solution. exit when ... will skip to the end of the loop, it's just that your loop ends in the middle of the process, so there's more code that follows. |
Author: | mrfungu [ Sun Dec 02, 2007 9:25 pm ] |
Post subject: | RE:Button and Animation working at same time |
the only problem with a return statement is that it will only terminate a proc. if i use an if statement, would i check if flag is still false every.. 5 pixels? and once it becomes true then it will return to menu? i dont understand. the animation should not be WORKING. I just realized that as soon as the menu runs or the program runs, "flag" is declared as true. |