I've begun learning Qbasic. For a beginner exercise, I started with a simple text game. A mountain is located "north", and when you type "north" the console should print "Mountain" after pressing Enter. However, when "north" is typed and Enter is pressed, the code is not being executed. Is this just a beginner's mistake? Should I be pressing something different than Enter?
Here's the code:
CLS
PRINT "There is a mountain to the North"
PRINT "There is a cactus to the East"
PRINT "There is a river to the South"
PRINT "There is a shack to the East"
PRINT " "
INPUT "Type a direction:", direction$
IF direction$ = "north" THEN PRINT "Mountain"
And the output from repl.it:
QBasic (qb.js)
Copyright (c) 2010 Steve Hanov
:
There is a mountain to the North
There is a cactus to the East
There is a river to the South
There is a shack to the East
:
Type a direction: north
:
Your code works just fine when running QBasic in DOSBox, but apparently the QB JavaScript library used by repl.it doesn't work quite as QBasic does. When you press Enter, the input should just end, and the end-of-line sequence shouldn't be stored (or should be removed automatically). Unfortunately, the end-of-line sequence was not removed by the JavaScript library. The result is that the following works when it wouldn't work in QBasic:
IF direction$ = "north" + CHR$(10) THEN PRINT "Mountain"
In fact, I added a simple alternative to test the interpreter and received a parse error before I figured out the problem with CHR$(10)
:
IF direction$ = "north" THEN PRINT "Mountain" ELSE PRINT "Not Mountain"
Based on this problem, I suggest running your program using the real thing (in a DOS emulator like DOSBox) or even something like FreeBASIC or QB64, both of which are based on QBasic and retain the same syntax, though I think QB64 is perhaps a little more compatible with the original.