Qbasicnews.com
October 18, 2019, 11:33:39 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: error when checking  (Read 4433 times)
MNDRBNDR
Member
*
Posts: 46



« on: February 04, 2005, 02:24:56 PM »

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?
Logged

o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #1 on: February 04, 2005, 02:26:44 PM »

Can we see the rest of the code?
Logged
MNDRBNDR
Member
*
Posts: 46



« Reply #2 on: February 04, 2005, 02:29:37 PM »

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
Logged

o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
MNDRBNDR
Member
*
Posts: 46



« Reply #3 on: February 04, 2005, 02:35:56 PM »

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
Logged

o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #4 on: February 04, 2005, 02:56:20 PM »

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"...
Logged
steven_basic
Senior Member
**
Posts: 244


WWW
« Reply #5 on: February 04, 2005, 03:06:55 PM »

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?
Logged

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!"
steven_basic
Senior Member
**
Posts: 244


WWW
« Reply #6 on: February 04, 2005, 03:19:19 PM »

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.
Logged

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!"
ShadowWolf
Wandering Guru
***
Posts: 389



« Reply #7 on: February 04, 2005, 03:20:26 PM »

Grrr GOSUB why did victor have to add that Sad i know i know backwords compatiblity but it makes code so unclean.
Logged
MNDRBNDR
Member
*
Posts: 46



« Reply #8 on: February 04, 2005, 03:22:28 PM »

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

o live is to die, to die is to expel, to expel is to exist is to live without knowing to be
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!