Qbasicnews.com
error when checking - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: error when checking (/thread-5928.html)



error when checking - MNDRBNDR - 02-04-2005

my code is this
if a$=b$ then exit do
evidently this isnt all my code but the freebasic program simply doesnt check if a$=b$ it just skips the check and exits do , it assumes that a$=b$ any idea how to fix this problem?


error when checking - Sterling Christensen - 02-04-2005

Can we see the rest of the code?


here ya go - MNDRBNDR - 02-04-2005

Code:
SETUP:
CLS
SCREEN 12
SLEEP 240
DIM X AS INTEGER,Y AS INTEGER, BUTTONS AS INTEGER
DIM STATUS(200)
DIM SEQ(200)
CIRCLE (300,150),50,4
CIRCLE (200,250),50,2
CIRCLE (400,250),50,3
CIRCLE (300,350),50,7
LENGTHOFSEQUENCE=5
B$=""
A$=""

GAME:
GOSUB MAKESEQUENCE
LOCATE 25,25:PRINT A$
LOCATE 26,25:PRINT B$
SLEEP 500
DO
A$=INKEY$
IF A$=CHR$(255)+"X" THEN SYSTEM
IF A$=CHR$(27) THEN SYSTEM
GETMOUSE X,Y,,BUTTONS
IF X>249 AND X<351 AND Y>101 AND Y<201 AND BUTTONS=1 THEN  B$=B$+"T":GOSUB TOPLIGHT
IF X>149 AND X<251 AND Y>200 AND Y<302 AND BUTTONS=1 THEN  B$=B$+"L":GOSUB LEFTLIGHT
IF X>349 AND X<451 AND Y>200 AND Y<302 AND BUTTONS=1 THEN  B$=B$+"R":GOSUB RIGHTLIGHT
IF X>249 AND X<351 AND Y>298 AND Y<402 AND BUTTONS=1 THEN  B$=B$+"B":GOSUB BOTTOMLIGHT
IF A$=B$ THEN EXIT DO
LOOP
LOCATE 24,25:PRINT "EXITED"
SLEEP 500
LENGTHOFSEQUENCE=LENGTHOFSEQUENCE+1
A$=""
B$=""
GOTO GAME

LOSE:
LOCATE 25,25:PRINT "SORRY"
SLEEP 300
GOSUB GAME

MAKESEQUENCE:
FOR T=1 TO LENGTHOFSEQUENCE
SEQINT=INT(RND(1)*5)
IF SEQINT=1 THEN A$=A$+"T":GOSUB TOPLIGHT
IF SEQINT=2 THEN A$=A$+"B":GOSUB BOTTOMLIGHT
IF SEQINT=3 THEN A$=A$+"L":GOSUB LEFTLIGHT
IF SEQINT=4 THEN A$=A$+"R":GOSUB RIGHTLIGHT
IF SEQINT=5 THEN A$=A$+"T":GOSUB TOPLIGHT
NEXT T
RETURN

TOPLIGHT:
FOR R=49 TO 1 STEP-1
CIRCLE (300,150),R,4
NEXT R
SLEEP 160
FOR R=49 TO 1 STEP-1
CIRCLE(300,150),R,0
NEXT R
RETURN

BOTTOMLIGHT:
FOR R=49 TO 1 STEP-1
CIRCLE (300,350),R,7
NEXT R
SLEEP 160
FOR R=49 TO 1 STEP-1
CIRCLE(300,350),R,0
NEXT R
RETURN

LEFTLIGHT:
FOR R=49 TO 1 STEP-1
CIRCLE (200,250),R,2
NEXT R
SLEEP 160
FOR R=49 TO 1 STEP-1
CIRCLE(200,250),R,0
NEXT R
RETURN

RIGHTLIGHT:
FOR R=49 TO 1 STEP-1
CIRCLE (400,250),R,3
NEXT R
SLEEP 160
FOR R=49 TO 1 STEP-1
CIRCLE(400,250),R,0
NEXT R
RETURN



this is it - MNDRBNDR - 02-04-2005

so what do you think ive added a couple lines in there just simply to error check and thats why i ended up here asking for help


error when checking - Sterling Christensen - 02-04-2005

A$ seems to be serving two purposes here. Are you overwriting a useful value in A$ when you A$=INKEY$ ? Maybe you meant there to be two separate variables but accidentally used the same letter?

For example, A$ = INKEY$ might set A$ to CHR$(255) + "H" (if the user presses the up arrow key), and then later MAKESEQUENCE might randomly change that to CHR$(255) + "H" + "T"...


error when checking - steven_basic - 02-04-2005

You are testing for A$ and B$ to be empty ("") then exiting the DO Loop. If no key is pressed, then A$ and B$ both = "" and the do loop exits.


Code:
DO
  sleep 100
  A$=INKEY$

This will slow things down enough to get a keypress in...

However, as soon as the loop cycles again with no immediate keypress, it bails out again.

Maybe a logic restructure for what you want to accomplish is in order?


error when checking - steven_basic - 02-04-2005

Looking closely at the code:

You set A$ and B$ to be "" (empty).

You call a routine to make A$ a set of "TLRB" string.

You enter the loop and immediately set A$ to be INKEY$ which will clear A$ out ("") if no key is pressed.

If A$ = B$, which at this point they both do, the the loop is exited.


error when checking - ShadowWolf - 02-04-2005

Grrr GOSUB why did victor have to add that Sad i know i know backwords compatiblity but it makes code so unclean.


that was it - MNDRBNDR - 02-04-2005

that's what it was thank you i cant believe i overlooked something as simple as that muchly apreciated thank you