Tip: Use an a/b choice.

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Wargod2293
Tip: Use an a/b choice.

Post by Wargod2293 » Fri Nov 05, 2004 1:26 am

This tip was designed for beginners in Qbasic. The following can be used for a process in which you need somthing to happen on/off repeatedly.

Code: Select all

variable = 0
do
if variable > 1 then
variable = variable - 2
end if
loop until vatiable < 2
if variable = 1 then

step 1

else

step 2

end if
This is probably basic knowledge to all of you, but I'm only in the ninth grade and have only made a handful of games, and therefore this is useful to my peers.

Buff
Jr. Member
Posts:22
Joined:Wed May 19, 2004 3:07 pm
Contact:

Post by Buff » Sat Nov 06, 2004 1:37 am

How about this.

Code: Select all

If YourChoice& then
  YourChoice&=0
else
  YourChoice&=1
end if
Print something on the screen here

'somewhere else  in the program
'responds to the 'choice' you made
If YourChoice& then
  yourcode here
else
  yourcode here
end if

Visiter

Use an a/b choice

Post by Visiter » Sat Dec 25, 2004 6:08 am

If, for example, you are toggling between two players in a game I like to use:

Code: Select all

Player% = -Player%
So Player% will always equal either one (1) or negative one (-1) and will toggle from one to the other each time the instruction is executed.

I'm not certain what your objective is.

Regards.

Dr_Davenstein
QBasic God
Posts:166
Joined:Tue Mar 25, 2003 12:45 am
Location:U.S.A.
Contact:

Post by Dr_Davenstein » Sat Dec 25, 2004 9:14 am

Why not just use a boolean operator? ;)

switch = NOT switch

If switch Then
'Evaluate
Else
'Dont
End If

That's the method I prefer.
Come check out [url=http://www.freebasic.net/forum/index.php]FreeBASIC[/url]. The syntax is based on QuickBasic, but it expands to use pointers, operator overloading, etc... The list goes on and on!

Post Reply