Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 using buttons
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
adams




PostPosted: Mon May 16, 2005 7:32 pm   Post subject: using buttons

i need help with this program.
It creates 6 buttons for a trivia question.(i will be doing multiple questions)
I want to show them one at a time

For question 1 when any of the buttons are pressed the screen clears and shows either right or wrong (which is what I want). But it does not go to the next question, the screen just stays blank. How can i make it go to question 2 and then the 3rd etc...(is there a "go to" command of some type?? HELP!!! note : I called the buttons in the second question because i couldn't make them numbers.

correct me on anything else if you wish.

[/code]
end Brazil
procedure Italy
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
end Italy
procedure Germany
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
end Germany

%buttons below (location and what will be displayed on the button)
var button1 : int := GUI.CreateButton (100, 100, 20, "France", France)
var button2 : int := GUI.CreateButton (100, 130, 20, "England", England)
var button3 : int := GUI.CreateButton (100, 160, 20, "Spain", Spain)
var button4 : int := GUI.CreateButton (100, 190, 20, "Brazil", Brazil)
var button5 : int := GUI.CreateButton (100, 220, 20, "Italy", Italy)
var button6 : int := GUI.CreateButton (100, 250, 20, "Germany", Germany)
loop
exit when GUI.ProcessEvent
end loop

%**********question 2**********

Font.Draw ("When did the sport become recognized?", 0, 375, font1, black)

%below displays what will appear after a button is selected
procedure example1
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
end example1
procedure example2
Font.Draw ("Wrong", 0, 50, font1, black)
delay (1250)
cls
end example2
procedure example3
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
end example3
procedure example4
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
end example4
procedure example5
cls
Font.Draw ("Right", 0, 50, font2, black)
delay (1250)
cls
end example5
procedure example6
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
end example6

%buttons below (location and what will be displayed on the button)
var button7 : int := GUI.CreateButton (100, 100, 20, "1894", example1)
var button8 : int := GUI.CreateButton (100, 130, 20, "1855", example2)
var button9 : int := GUI.CreateButton (100, 160, 20, "1848", example3)
var button10 : int := GUI.CreateButton (100, 190, 20, "1877", example4)
var button11 : int := GUI.CreateButton (100, 220, 20, "1863", example5)
var button12 : int := GUI.CreateButton (100, 250, 20, "1886", example6)
loop
exit when GUI.ProcessEvent
end loop
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon May 16, 2005 8:19 pm   Post subject: (No subject)

1) Hello. Welcome.

2) Tags are not that difficult to use. If you don't want to manually type out the []'s, the simply highlight your chosen text and click the "Code" button in the Post options.

3) Please don't use titles such as "I need help", or "Please help". This helps no one. If we do not know what the thread is about we might not feel like opening it. In addition, there is a Sticky dedicated to this warning, as well as a post on the Main Page.

4) Change your thread title, fix your post, and I'm sure people will drop by to give you tips.
sockoo




PostPosted: Mon May 16, 2005 8:55 pm   Post subject: (No subject)

Ok if i understand correctly here's is what you have to do .. and assuming you know how to use procedures cause u'v already used them

put each button in its own procedure .. and when you want that button to be called .. well call it for example

code:

proc Button1
%Button Here
%Procedure with dispose of button
%name of procedure with question
end Button1

proc Button2
%Another button here
%Procedure with dispose of button
%name of procedure with question (can either be put here or with dispose)
end button

proc question
put " Why dont i follow the rules ?  "
get answer
cls
%name next buttton procedure you wish to go to
sockoo




PostPosted: Mon May 16, 2005 9:00 pm   Post subject: (No subject)

code:

Font.Draw ("When did the sport become recognized?", 0, 375, font1, black)

%below displays what will appear after a button is selected

procedure example1
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
button
end example1

procedure example2
Font.Draw ("Wrong", 0, 50, font1, black)
delay (1250)
cls
button
end example2

procedure example3
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
button
end example3

procedure example4
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
button
end example4

procedure example5
cls
Font.Draw ("Right", 0, 50, font2, black)
delay (1250)
cls
button
end example5

procedure example6
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
button
end example6

proc button
%buttons below (location and what will be displayed on the button)
var button7 : int := GUI.CreateButton (100, 100, 20, "1894", example1)
var button8 : int := GUI.CreateButton (100, 130, 20, "1855", example2)
var button9 : int := GUI.CreateButton (100, 160, 20, "1848", example3)
var button10 : int := GUI.CreateButton (100, 190, 20, "1877", example4)
var button11 : int := GUI.CreateButton (100, 220, 20, "1863", example5)
var button12 : int := GUI.CreateButton (100, 250, 20, "1886", example6)
end button

loop
exit when GUI.ProcessEvent
end loop


Assuming you wanna keep going back to those same buttons .. i modified ur code so it would do so
sockoo




PostPosted: Tue May 17, 2005 12:08 pm   Post subject: (No subject)

My question for you tho .. is why have .. 6 different procedures with almost the same thing in them why not just have 2 ? .. (one for right and one for wrong .. for example: )



code:

Font.Draw ("When did the sport become recognized?", 0, 375, font1, black)

%below displays what will appear after a button is selected

procedure example5
cls
Font.Draw ("Right", 0, 50, font2, black)
delay (1250)
cls
button
end example5

procedure example6
cls
Font.Draw ("Wrong", 0, 50, font2, black)
delay (1250)
cls
button
end example6

proc button
%buttons below (location and what will be displayed on the button)
var button7 : int := GUI.CreateButton (100, 100, 20, "1894", example6)
var button8 : int := GUI.CreateButton (100, 130, 20, "1855", example6)
var button9 : int := GUI.CreateButton (100, 160, 20, "1848", example6)
var button10 : int := GUI.CreateButton (100, 190, 20, "1877", example6)
var button11 : int := GUI.CreateButton (100, 220, 20, "1863", example5)
var button12 : int := GUI.CreateButton (100, 250, 20, "1886", example6)
end button

loop
exit when GUI.ProcessEvent
end loop
adams




PostPosted: Tue May 17, 2005 8:12 pm   Post subject: (No subject)

thank you sockoo. im new to making buttons. I just looked at the turing reference thing and took it from there
adams




PostPosted: Wed May 18, 2005 5:54 pm   Post subject: (No subject)

ok i appreciate the help but i still havent had my question answered.
all i want to do is get from question 1 to question 2 and continue the trivia.
i think the problem is with the "exit when" in the loop. or i need a go to command of some type (if there is one).

code:
import GUI

var pic : int := Pic.FileNew ("soccer stadium.BMP")
var font1 : int := Font.New ("Arial:50:bold")
var font2 : int := Font.New ("Arial:50:bold")
var font3 : int := Font.New ("Arial:16:bold")

%below displays what will appear after a button is selected
procedure wrong
    Font.Draw ("Wrong", 0, 50, font2, black)
end wrong
procedure right
Font.Draw ("Right", 0, 50, font1, black)
end right

%***************question 1**************
Pic.Draw (pic, 0, 0, picMerge)
Font.Draw ("From which country did Soccer originate?", 0, 375, font3, white)
%buttons below (location and what will be displayed on the button)
var button1 : int := GUI.CreateButton (100, 100, 20, "France", wrong)
var button2 : int := GUI.CreateButton (100, 130, 20, "England", right)
var button3 : int := GUI.CreateButton (100, 160, 20, "Spain", wrong)
var button4 : int := GUI.CreateButton (100, 190, 20, "Brazil", wrong)
var button5 : int := GUI.CreateButton (100, 220, 20, "Italy", wrong)
var button6 : int := GUI.CreateButton (100, 250, 20, "Germany", wrong)
loop
    exit when GUI.ProcessEvent
end loop

%**********question 2**********
Pic.Draw (pic, 0, 0, picMerge)
Font.Draw ("When did the sport become recognized?", 0, 375, font3, white)

%buttons below (location and what will be displayed on the button)
var button7 : int := GUI.CreateButton (100, 100, 20, "1894", wrong)
var button8 : int := GUI.CreateButton (100, 130, 20, "1855", wrong)
var button9 : int := GUI.CreateButton (100, 160, 20, "1848", wrong)
var button10 : int := GUI.CreateButton (100, 190, 20, "1877", wrong)
var button11 : int := GUI.CreateButton (100, 220, 20, "1863", right)
var button12 : int := GUI.CreateButton (100, 250, 20, "1886", wrong)
loop
    exit when GUI.ProcessEvent
end loop
sockoo




PostPosted: Thu May 19, 2005 8:54 am   Post subject: (No subject)

i fixed up ur code it goes over to the next question now all you need to do is fix up ur buttons soo after it gets it wrong on the second question it re shows .. those same buttons not the ones from before .. i'd help you out .. but class is over so0o i'll have a look at it when i get home if i have the time .. gl!

code:


import GUI in "%oot/support/lib/GUI"
var pic : int := Pic.FileNew ("soccer stadium.BMP")
var font1 : int := Font.New ("Arial:50:bold")
var font2 : int := Font.New ("Arial:50:bold")
var font3 : int := Font.New ("Arial:16:bold")
forward proc button1
forward proc button
forward proc right1
forward proc wrong1
%below displays what will appear after a button is selected
procedure wrong
    Font.Draw ("Wrong", 0, 50, font2, black)
    delay (1000)
    cls
    button1
end wrong
procedure right
Font.Draw ("Right", 0, 50, font1, black)
delay (1000)
cls
button
end right

body proc button1
%***************question 1**************
Pic.Draw (pic, 5, 5, picMerge)
Font.Draw ("From which country did Soccer originate?", 0, 375, font3, white)
%buttons below (location and what will be displayed on the button)
var button1 : int := GUI.CreateButton (100, 100, 20, "France", wrong)
var button2 : int := GUI.CreateButton (100, 130, 20, "England", right)
var button3 : int := GUI.CreateButton (100, 160, 20, "Spain", wrong)
var button4 : int := GUI.CreateButton (100, 190, 20, "Brazil", wrong)
var button5 : int := GUI.CreateButton (100, 220, 20, "Italy", wrong)
var button6 : int := GUI.CreateButton (100, 250, 20, "Germany", wrong)
end button1

%**********question 2**********
Pic.Draw (pic, 0, 0, picMerge)
Font.Draw ("When did the sport become recognized?", 0, 375, font3, white)
body proc right1

Font.Draw ("Right", 0, 50, font1, black)

end right1

body proc wrong1
Font.Draw ("Right", 0, 50, font1, black)

end wrong1

body proc button
%buttons below (location and what will be displayed on the button)
var button7 : int := GUI.CreateButton (100, 100, 20, "1894", wrong1)
var button8 : int := GUI.CreateButton (100, 130, 20, "1855", wrong1)
var button9 : int := GUI.CreateButton (100, 160, 20, "1848", wrong1)
var button10 : int := GUI.CreateButton (100, 190, 20, "1877", wrong1)
var button11 : int := GUI.CreateButton (100, 220, 20, "1863", right1)
var button12 : int := GUI.CreateButton (100, 250, 20, "1886", wrong1)
end button

button1
loop
    exit when GUI.ProcessEvent
end loop
Sponsor
Sponsor
Sponsor
sponsor
adams




PostPosted: Thu May 19, 2005 10:51 am   Post subject: (No subject)

sockoo can you please put comments to help me to understand what all the "forward proc" and "body proc" etc... do?
adams




PostPosted: Thu May 19, 2005 4:14 pm   Post subject: (No subject)

i found a little problem. When i click the right answer (1863) in the second question it says "wrong". If you click and hold "1855" you see "England" which is the right answer for the first question. So "1855" ends up being the right answer in the second question. I need the program to completely forget the last question.
sockoo




PostPosted: Thu May 19, 2005 5:13 pm   Post subject: (No subject)

adams wrote:
sockoo can you please put comments to help me to understand what all the "forward proc" and "body proc" etc... do?


all those are doing is calling the procedure at the start of ur program .. not giving u the error " Bla Bla has no been declared .. "

and i know that error is that .. i told you it was there .. its your program .. im not going to program the whole thing for you .. even tho that'd be really nice of me Razz .. , try n figure it out ur self .. what are you going to learn with me doing if for you ?
adams




PostPosted: Fri May 20, 2005 10:01 am   Post subject: (No subject)

ok i figured out what "body pro" and "forward proc" do. But i dont know how to fix my buttons part. If you click and hold on a button and then take the mouse off it shows the name of the button from the last question.
adams




PostPosted: Fri May 20, 2005 11:09 am   Post subject: (No subject)

I think I need to use GUI.Dispose but I don't know the right spot to put it in. When I put it in a place that isn't in the same "body proc" that contains the buttons I want to delete i get 'button 1,2,3,4,5,6' not declared. But if I put it in the same "body proc" that contain the buttons I want to delete the buttons will not show. heres what I have so far.

code:
import GUI in "%oot/support/lib/GUI"
setscreen ("graphics:vga")
var pic : int := Pic.FileNew ("soccer_stadium.jpg")
var font1 : int := Font.New ("Arial:50:bold")
var font2 : int := Font.New ("Arial:50:bold")
var font3 : int := Font.New ("Arial:16:bold")
var becknum, beckham : int
becknum := 1
forward proc b1
forward proc b2
forward proc b3
forward proc b4

forward proc right1
forward proc right2
forward proc right3
forward proc right4

forward proc wrong1
forward proc wrong2
forward proc wrong3
forward proc wrong4
%***************question 1**************
%below displays what will appear after a button is selected
body proc wrong1
    cls
    Font.Draw ("Wrong", 0, 50, font2, black)
    b2
end wrong1
body proc right1
    cls
    Font.Draw ("Right", 0, 50, font1, black)
    delay (1250)
    cls
    %omit comments below
    %loop
    %        delay (60)
    %        beckham := Pic.FileNew ("beckham" + intstr (becknum) + ".BMP")
    %        Pic.Draw (beckham, 175, 100, picCopy)
    %        becknum := becknum + 1
    %        exit when becknum = 210
    %    end loop
b2
end right1

body proc b1
    delay (1250)
    cls
    Pic.Draw (pic, 0, 0, picMerge)
    Font.Draw ("From which country did Soccer originate?", 0, 375, font3, white)
    %buttons below (location and what will be displayed on the button)
    var button1 : int := GUI.CreateButton (100, 100, 20, "France", wrong1)
    var button2 : int := GUI.CreateButton (100, 130, 20, "England", right1)
    var button3 : int := GUI.CreateButton (100, 160, 20, "Spain", wrong1)
    var button4 : int := GUI.CreateButton (100, 190, 20, "Brazil", wrong1)
    var button5 : int := GUI.CreateButton (100, 220, 20, "Italy", wrong1)
    var button6 : int := GUI.CreateButton (100, 250, 20, "Germany", wrong1)
end b1

%**********question 2**********
body proc wrong2
    cls
    Font.Draw ("Wrong", 0, 50, font1, black)
    b3
end wrong2
body proc right2
    cls
    Font.Draw ("Right", 0, 50, font1, black)
    b3
end right2

body proc b2
delay (1250)
    cls
    Pic.Draw (pic, 0, 0, picMerge)
    Font.Draw ("When did the sport become recognized?", 0, 375, font3, white)
    %buttons below (location and what will be displayed on the button)
    var button7 : int := GUI.CreateButton (100, 100, 20, "1894", wrong2)
    var button8 : int := GUI.CreateButton (100, 130, 20, "1855", wrong2)
    var button9 : int := GUI.CreateButton (100, 160, 20, "1848", wrong2)
    var button10 : int := GUI.CreateButton (100, 190, 20, "1877", wrong2)
    var button11 : int := GUI.CreateButton (100, 220, 20, "1863", right2)
    var button12 : int := GUI.CreateButton (100, 250, 20, "1886", wrong2)
end b2

%**********question 3**********
body proc right3
    cls
    Font.Draw ("Right", 0, 50, font1, black)
end right3
body proc wrong3
    cls
    Font.Draw ("Wrong", 0, 50, font1, black)
end wrong3

body proc b3
    delay (1250)
    cls
    Pic.Draw (pic, 0, 0, picMerge)
    Font.Draw ("What country and City does FIFA originate?", 0, 375, font3, white)
    %buttons below (location and what will be displayed on the button)
    var button13 : int := GUI.CreateButton (100, 100, 20, "Paris, France", right3)
    var button14 : int := GUI.CreateButton (100, 130, 20, "London, England", wrong3)
    var button15 : int := GUI.CreateButton (100, 160, 20, "Toronto, Canada", wrong3)
    var button16 : int := GUI.CreateButton (100, 190, 20, "Budapest, Hungary", wrong3)
    var button17 : int := GUI.CreateButton (100, 220, 20, "New York, United States", wrong3)
    var button18 : int := GUI.CreateButton (100, 250, 20, "Berlin, Germany", wrong3)
end b3

%*********question 4**********
body proc right4
    cls
    Font.Draw ("Right", 0, 50, font1, black)
end right4
body proc wrong4
    cls
    Font.Draw ("Wrong", 0, 50, font1, black)
end wrong4

body proc b4
    delay (1250)
    cls
    Pic.Draw (pic, 0, 0, picMerge)
    Font.Draw ("Where did the first Olympic Soccer Tournament take place?", 0, 375, font3, white)
    %buttons below (location and what will be displayed on the button)
    var button19 : int := GUI.CreateButton (100, 100, 20, "Poland", wrong4)
    var button20 : int := GUI.CreateButton (100, 130, 20, "Scotland", wrong4)
    var button21 : int := GUI.CreateButton (100, 160, 20, "England", wrong4)
    var button22 : int := GUI.CreateButton (100, 190, 20, "Portugal", right4)
    var button23 : int := GUI.CreateButton (100, 220, 20, "Brazil", right4)
    var button24 : int := GUI.CreateButton (100, 250, 20, "Spain", wrong4)
end b4

b1
loop
    exit when GUI.ProcessEvent
end loop
sockoo




PostPosted: Fri May 20, 2005 2:52 pm   Post subject: (No subject)

what you will want to do is put lets say .. buttons 1- 7 ? ... or whatever buttons you use for ur first question .. put the those dispose buttons in a procedure then before you go to draw new buttons .. (in proc b2 i beleive) write the name of the procedure to dispose of the buttons from 1-7 .. here's an example of what i mean

code:

proc dispose
GUI.dispose .. bla bla w/e the cmd is ( you have to list every button you want to be disposed of and u'll need more then one of these .. u'll need one for just about every question )
end dispose

body proc b2
%%%%% Put Name Of Disposal Procedure Here! %%%%%%%%% In This Case it would be dispose
delay (1250)
    cls
    Pic.Draw (pic, 0, 0, picMerge)
    Font.Draw ("When did the sport become recognized?", 0, 375, font3, white)
    %buttons below (location and what will be displayed on the button)
    var button7 : int := GUI.CreateButton (100, 100, 20, "1894", wrong2)
    var button8 : int := GUI.CreateButton (100, 130, 20, "1855", wrong2)
    var button9 : int := GUI.CreateButton (100, 160, 20, "1848", wrong2)
    var button10 : int := GUI.CreateButton (100, 190, 20, "1877", wrong2)
    var button11 : int := GUI.CreateButton (100, 220, 20, "1863", right2)
    var button12 : int := GUI.CreateButton (100, 250, 20, "1886", wrong2)
end b2
adams




PostPosted: Fri May 20, 2005 9:18 pm   Post subject: (No subject)

ok i do that but it says that button1 has not been declared. And when i put all of them in their own GUI.Dispose they are all said not to be declared.

code:
import GUI in "%oot/support/lib/GUI"
setscreen ("graphics:vga")

var font1 : int := Font.New ("Arial:50:bold")
var font2 : int := Font.New ("Arial:50:bold")
var font3 : int := Font.New ("Arial:16:bold")

forward proc b1
forward proc b2
forward proc b3
forward proc b4

forward proc right1
forward proc right2
forward proc right3
forward proc right4

forward proc wrong1
forward proc wrong2
forward proc wrong3
forward proc wrong4

%***************question 1**************
%below displays what will appear after a button is selected
body proc wrong1
    cls
    Font.Draw ("Wrong", 0, 50, font2, black)
    b2
end wrong1
body proc right1
    cls
    Font.Draw ("Right", 0, 50, font1, black)
    delay (1250)
    cls
    %omit comments below
    %loop
    %        delay (60)
    %        beckham := Pic.FileNew ("beckham" + intstr (becknum) + ".BMP")
    %        Pic.Draw (beckham, 175, 100, picCopy)
    %        becknum := becknum + 1
    %        exit when becknum = 210
    %    end loop
    b2
end right1

body proc b1
    delay (1250)
    cls
Font.Draw ("From which country did Soccer originate?", 0, 375, font3, white)
    %buttons below (location and what will be displayed on the button)
    var button1 : int := GUI.CreateButton (100, 100, 20, "France", wrong1)
    var button2 : int := GUI.CreateButton (100, 130, 20, "England", right1)
    var button3 : int := GUI.CreateButton (100, 160, 20, "Spain", wrong1)
    var button4 : int := GUI.CreateButton (100, 190, 20, "Brazil", wrong1)
    var button5 : int := GUI.CreateButton (100, 220, 20, "Italy", wrong1)
    var button6 : int := GUI.CreateButton (100, 250, 20, "Germany", wrong1)
end b1

%**********question 2**********
body proc wrong2
    cls
    Font.Draw ("Wrong", 0, 50, font1, black)
    b3
end wrong2
body proc right2
    cls
    Font.Draw ("Right", 0, 50, font1, black)
    b3
end right2
%dispos of buttons in question 1
proc dispose
    GUI.Dispose (button1, button2, button3, button4, button5, button6)
end dispose

body proc b2
    dispose
    delay (1250)
    cls
Font.Draw ("When did the sport become recognized?", 0, 375, font3, white)
    %buttons below (location and what will be displayed on the button)
    var button7 : int := GUI.CreateButton (100, 100, 20, "1894", wrong2)
    var button8 : int := GUI.CreateButton (100, 130, 20, "1855", wrong2)
    var button9 : int := GUI.CreateButton (100, 160, 20, "1848", wrong2)
    var button10 : int := GUI.CreateButton (100, 190, 20, "1877", wrong2)
    var button11 : int := GUI.CreateButton (100, 220, 20, "1863", right2)
    var button12 : int := GUI.CreateButton (100, 250, 20, "1886", wrong2)
end b2

b1
loop
    exit when GUI.ProcessEvent
end loop
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: