Hi,
I would like to write a program using buttons. So, for example, when the program is first launched, a screen appears with a number of options. Let's say if F1' /> the program is told to Goto 1, and the code under Lbl 1 would come on screen, and if the program was executed again and F2' /> was pressed, then Goto 2 would be shown for example.
I assume this uses loops but I'm quite new to programming and don't know how to use loops to make buttons.
Hope you can help. Thanks.
Alf <:3D~
How To Create Buttons Within Programs?
Started by
Alfie Stoppani
, Mar 02 2012 05:41 PM
5 replies to this topic
#1
Posted 02 March 2012 - 05:41 PM
#2
Posted 02 March 2012 - 05:49 PM
Ok.
Here is a simple way to do it:
Hope that helps
Here is a simple way to do it:
While not Getkey //loop while no button is pressed Getkey -> G WhileEnd G=79 => Goto 1 //If F1 is pressed, goto 1 (79 is the code for F1) G=29 => Goto 2 Lbl 1 Stuff to do if f1 is pressed Lbl 2 stuff to do if f2 is pressed
Hope that helps
#3
Posted 03 March 2012 - 06:20 PM
I can't get your code to work, it just shows the things in labels 1 & 2 simultaneously, and seems to bypass the getkey looping bit.
I tried this code: [codebox]Goto 3
Lbl 1
"I Just Pressed F1"
Goto 0
Lbl 2
"I Just Pressed F2"
Goto 0
Lbl 3
While Not Getkey
Getkey -> G
WhileEnd
If G=79
Then Goto 1
If End
If G=69
Then Goto 2
If End
Lbl 0[/codebox]
And it doesn't work, just says 'Done'. What am I doing wrong with this modification to the previous code?
Alf.
I tried this code: [codebox]Goto 3
Lbl 1
"I Just Pressed F1"
Goto 0
Lbl 2
"I Just Pressed F2"
Goto 0
Lbl 3
While Not Getkey
Getkey -> G
WhileEnd
If G=79
Then Goto 1
If End
If G=69
Then Goto 2
If End
Lbl 0[/codebox]
And it doesn't work, just says 'Done'. What am I doing wrong with this modification to the previous code?
Alf.
#4
Posted 26 March 2012 - 06:39 PM
Oh wait, try this:
While Getkey=0 or Getkey =21 //loop while no button is pressed Getkey -> G WhileEnd G=79 => Goto 1 //If F1 is pressed, goto 1 (79 is the code for F1) G=29 => Goto 2 Lbl 1 Stuff to do if f1 is pressed Lbl 2 stuff to do if f2 is pressed
#5
Posted 08 February 2014 - 01:49 AM
Maybe you can use Do LpWhile to loop unless f1 or f2 is pressed:
Do Getkey->G LpWhile G≠79 And G≠29 G=79 => Goto 1 G=29 => Goto 2 Lbl 1 Stuff to do if f1 is pressed Lbl 2 stuff to do if f2 is pressed
#6
Posted 09 February 2014 - 03:36 AM
That works.
Also,
Also,
Lbl
's and goto
's are not the best coding practices. Maybe this code would be faster (slightly)?Do Getkey->G LpWhile G≠79 And G≠29 If G=79 Then 'Stuff to do if f1 is pressed If G=29 Then 'stuff to do if f2 is pressed
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users