For the purposes of this, assume I'm using Ye Olde QuickBASIC PDS 7.1. Yeah, it's antique. I know. But I can code in it -- sorta. (It's better than the copy of QBASIC on my 386, which is where I started -- in the late 90s!) I'd say that 90-95% of what is in QuickBASIC 7.1 will port over to QB64 (which aims for QuickBASIC 4.5 compatibility) as needed. I'll handle the transition if and when it happens. For now, let's stick to PDS 7.1, since I've a friend there.
OK, now onto the actual relevant stuff...
I have an appallingly-coded text adventure, where the input goes something like this...
Code: Select all
200 PRINT "What do you do"; INPUT$
210 IF INPUT$ = "GET CUP" THEN GOTO 1280
220 IF INPUT$ = "DROP GEM" THEN GOTO 1290
...
Because I can't code a parser. I *can*, however, give myself carpal tunnel syndrome coding a game (thankfully this hasn't happened... yet...)
The best idea I have so far is to have it like this... (pseudocode warning!)
Code: Select all
get [b]INPUT$[/b] from user
if INPUT$ contains "GET" then
if INPUT$ contains "CUP" goto [line #]
if INPUT$ contains "BOTTLE" goto [a different line #]
...
if INPUT$ contains "DROP" then
if INPUT$ contains "FLASHLIGHT" goto [line #]
if INPUT$ contains "GEM" goto [another line #]
...
There's another problem I have, which can be addressed later... that of Inventory. In a proper game you can pick stuff up and carry it with you. (Imagine that!) In my game, since I can't code for beans, I had a global variable set up for each item with a one-character string indicating if it was in a location (eg "uld" upper ladder room) or in inventory (eg "inv") etc. The GEM in the game had a special condition -- if you d"DROP GEM", such a thing literally happens (SMASH oops), so it had a string for that (eg "brk") that triggered an alternate ending.
I believe what I *actually* need is a thing called an array variable, but I've no idea really how those work or how to set one up.
Having said that... I'd like some suggestions on how to implement a real parser that isn't hopelessly clumsy. It doesn't have to wow people, but I'd like it to be at least halfway to decent
@jamesbond,seaside: I looked at both of your examples. Couldn't really read either one -- jamesbond, yours was about parsing math (I'm horrible with math!) so I'm not sure I could use it anyways. Seaside, I've yet to get the hang of object oriented code, so I'm sorry, I just couldn't understand your example.