Qbasicnews.com

Full Version: IF, THEN problem...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
When I try to run, it says "type mismatch" and highlights the "y" and the THEN

Code:
1 INPUT T
2 IF T = "y" THEN GOTO 3
3 END IF

Anyone have some help?
Quote:When I try to run, it says "type mismatch" and highlights the "y" and the THEN

Code:
1 INPUT T
2 IF T = "y" THEN GOTO 3
3 END IF

Anyone have some help?

just a variable, by default, is an integer. "T" should be "T$"
the "$" makes is a string.
alternatively,
Code:
DIM T AS STRING
1 INPUT T
2 IF T = "y" THEN GOTO 3
3 END IF

Would also work and line 2 should be

Code:
2 IF T = "y" THEN

and line 3&4:

Code:
3 GOTO 3
4 END IF

or get rid of line 4 entirely.
or:
Code:
DEFstr a-m

that would make all variables that start with a-m a string. (so you wouldn't need a "$" after them)

DIM overides DEF.
Cool thanks! Were making an my pal and me are making an awesome space free-roming like every othor one before but better. Maybe. Then we ran into this little yet painfull roadblock. If you have ever played space trader for Palm Os, it's gona be like that. But alot more indepth and complicated.
That’s almost legible.
but thanks anyway.

and because i'm board:

just for the hell of it, take the code from your first post and the only change only the "T"

Code:
1 INPUT T$
2 IF T$ = "y" THEN GOTO 3
3 END IF

now run it. now fb bitches about "END IF" with no "IF"
that's because on line 2:

2 IF T$ = "y" THEN GOTO 3

you already completed the IF...THEN
so the END IF on line 3 is redundant.

and what if T$ isn't a "y"? now what? it should be:

Code:
1 INPUT T$
2 IF T$ = "y" THEN GOTO 3 ELSE GOTO 5
3 ? "You pressed ""y""."
4 SLEEP:END
5 ? "You didn't press ""y"""
6  SLEEP:END

or whatever.
Sorry about my illegible-ness. Its 2:30am and my brain is like, "I don't pity the fool!" And I'm like, woha, back to the qb. WHAT SYNTAX WHOS SYNTAX!!!!
I looked into the game "Space Traders". Good luck.

i don't think i could code that much less a mongoloid. :wink:

EDIT: this post was meant to be above the one obove this one.
Yah, lots of code. Lots and lots ofs pointless but so essential code. The battle engine and other logic take up most of the code. Thats why my friend is workin on the battle system and im over here posting in forums and making little planets and cool graphics. hehhhehehh.... ahhhh fine ill go help him mr. t.
Just out of curiosity, why are you using line numbers?
that's what i thought. it seems it would make programming more difficult.
Pages: 1 2