Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error when checking
#1
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?
o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
Reply
#2
Can we see the rest of the code?
Reply
#3
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
o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
Reply
#4
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
o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
Reply
#5
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"...
Reply
#6
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?
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#7
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.
ature has its way of warning a person away from danger: The distinct black and white coloration on a skunk, the chilling buzz of a rattlesanke, a redneck handing you his beer and saying "Watch this!"
Reply
#8
Grrr GOSUB why did victor have to add that Sad i know i know backwords compatiblity but it makes code so unclean.
Reply
#9
that's what it was thank you i cant believe i overlooked something as simple as that muchly apreciated thank you
o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)