Simple programming help

Started by
1 comment, last by Verg 16 years, 10 months ago
Well, I recently bought Game Programming for Teens which teaches you the language BlitzPlus. Everything so far has been easy to understand, yet when I attempted something of my own, it didn't work. My code is to generate a simple input/output procedure, just like that of an old DOS adventure game. So far the only input I can make which will make a response is a number. I'm trying to make it so that you can enter a line of text, or String$, as a choice. Here is my code: answer = Input$("you find yourself in a room with a cat. what will you do?") If answer = "pet cat" Then Print "You pick up the cat. The cat bites your face off. You are Dead." ElseIf answer = "kick the cat" Then Print "You kick the cat. The cat runs away crying. You win." EndIf Delay 10000 When the program loads and I put in my answer, nothing happens. I tried using String$ instead of Input$ for the answer variable, but that doesn't work. I know this may seem like a pathetic problem, and I'm sure I will learn how solve it as I progress in the book, but for now I'd like to get a quick response. -Thanks! [Edited by - Taran Shiro on June 2, 2007 1:14:05 PM]
Advertisement
Never heard of the language "BlitzPlus", though it does look a bit like BASIC.

I would guess that your tests (i.e. "If answer =") are wrong. It depends on what the "=" does, one would guess.

It may also be that what you input isn't what the variable is being set to. It may be including a carriage return at the end, for instance.

Without knowing the syntax of "BlitzPlus" it's hard to say.

For a simple debugging step, try:

Print answer

right after the input and see if it looks the same. Beyond that you'll just have to study the syntax of that language some more.
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
Actually just a little Google search turned up this:

http://www.blitzmax.com/bpdocs/command.php?name=If&ref=2d_cat

; IF THEN Example; Input the user's namename$=Input$("What is your name? "); Doesn't the person's name equal SHANE?If name$ = "Shane" ThenPrint "You are recognized, Shane! Welcome!"ElsePrint "Sorry, you don't belong here!"; End of the condition checkingEnd If


Seems you need to change your code to

...
answer$ = Input$("you find yourself in a room with a cat. what will you do?")

If answer$ = "pet cat" Then
Print "You pick up the cat. The cat bites your face off. You are Dead."

ElseIf answer$ = "kick the cat" Then

...

You were missing the "$" at the end of your variable name.
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]

This topic is closed to new replies.

Advertisement