Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 if state ments are making me mad!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
magicman




PostPosted: Tue Apr 20, 2004 4:43 pm   Post subject: if state ments are making me mad!!

when you are running my prg, after you enter your name and rank. then select south for the direction then the prg closes and says Variable has no value. What does that mean. here's my code
code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Final Fantasy. The Final Battle.            %
%By: Nathan Boucher.                         %
%copy writed by. Nathan boucher. c)          %
%Starting Date- April 13, 2004               %
%Final Date                                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
setscreen("graphics:max;max")
var rank : string
var abilities : string
var name : string
var strength : int := 1
var health : int := 100
var Def : int := 1
var agility : int := 1
var coins : int := 10
var direction : string
var answer : string
var password : string

put "WELCOME TO FINAL FANTASY- THE FINAL BATTLE!!!"
%delay (2500)
cls
put "What's your name?"
get name
put "What rank do you want?"
put "soldier"
put "wizard"
put "thief"
get rank
%The Soldiers Abilities.
if rank = "soldier" then
    put "Your abilities are:"
    put ""
    put "Rage."
    put "Super Attack."
    put "Heal."
    put ""
    put "Your strength is: ", strength + 3
    put "Your defence is: ", Def + 2
    put "Your agility is: ", agility + 1
    put "Your Health is: ", health
elsif


    %The Wizards Abilities.
        rank = "wizard" then
    put "Your abilities are:"
    put ""
    put "Fire."
    put "Lighting."
    put "Ice."
    put "Heal."
    put ""
    put "Your strength is: ", strength + 1
    put "Your defence is: ", Def + 1
    put "Your agility is: ", agility + 2
    put "Your Health is: ", health
elsif

    %The Thief's Abilities.
        rank = "thief" then
    put "Your abilities are:"
    put ""
    put "Steal Wepon."
    put "Assassination."
    put ""
    put "Your strength is: ", strength
    put "Your defence is: ", Def
    put "Your agility is: ", agility + 4
    put "Your Health is: ", health
end if
put "Hit any key to start the game..."

var ch : string (1)
getch (ch)

put "You are now entering the final battle. Have fun!"
%delay (4000)
cls
put skip
put "*************************************************"
put "*************************************************"
put "*************************************************"
put skip
put "*************************************************"
put "*************************************************"
put "*************************************************"
put skip
put "Wake up stranger."
put "Hey, what's your name??"
put "My name is ", name, "."
put skip
%delay (1000)
put "Well lets get started with your journey."


put "Do you want to go North, East, South or West??"
get direction

if direction = "north" then
    put "You see a bar in the distance. Do you want to go there??"
    get answer
end if

if answer = "yes" then
    put "You go into the bar and you see an elf. He asks you, ''Do you want a drink? It cost 5 coins.''"
    get answer
end if
if answer = "yes" then
    put "That will be 5 coins, thank you. You now have,", coins - 5, " coins left."
end if
if answer = "no" then
    put "Do you want to go East, South or West??"
    get direction
end if

if direction = "east" then
    put "There is a cave in the distance. Do you want to go there?"
    get answer
end if
if answer = "yes" then
    put "A man comes out of the darkness and says,'What's the password??'"
    get password
end if
if password = "time" then
    put "You may enter."
end if

if direction = "south" then
    put "There is a man in the shadow of the alley. Do you go up to him??"
    get answer
end if
if answer = "yes" then
    put "I have three riddles for you. Here they are."
    %delay (1000)
    put "Propane is either:"
    put "A)Flamable"
    put "B)Non-Flamable"
    put "C)All of the above"
    get answer
end if
if answer = "a" then
    put "You are correct."
end if
if answer = "b" then
    put "How dumb can you really be?"
end if
if answer = "c" then
    put "You are an insolate fool."
end if
%delay (1000)
put "The second riddle is:"
put "If a tree falls in the forest and nobody's around, does it make a sound??"
get answer
if answer = "yes" then
    put "You are correct."
end if
if answer = "no" then
    put "You are dumb as a door nob!!!"
end if
%delay (1000)
put "The last one is:"
put "If you clap with one hand, does it make a sound??"
get answer
if answer = "yes" then
    put "You are correct. The password to the cave is time."
end if
if answer = "no" then
    put "You are so dumb you loose the game!!!!!"
end if

if direction = "west" then
    put "You see a treasure chest. Do you want to oppen it????"
    get answer
end if
if answer = "yes" then
    put "You got 100 coins. You now have, ", coins + 100, "coins"
end if


thanks for the help. Very Happy Very Happy Laughing
Sponsor
Sponsor
Sponsor
sponsor
gamer




PostPosted: Tue Apr 20, 2004 4:50 pm   Post subject: (No subject)

becuz u didnt do the if statement for south,west,n east.....all u did is north
so then it'll skip the part of getting "answer", which leads to the "variable has no value" problem since the user couldnt enter values for "answer"

case structure is recommended
Delos




PostPosted: Tue Apr 20, 2004 4:51 pm   Post subject: (No subject)

Your 'if direction is north' statement preceeds your 'if direction is south' statement. Thus, your programme will check for 'answer' before it has been entered, and thus it does not exist yet.

You really need to tighten your code here. Have you heard of 'elsif's? If not, read up the tutorial on ifs in the Tutorials section.

One of Tony's many brainchildren.


Ah! Beaten to the reply!
gamer




PostPosted: Tue Apr 20, 2004 6:08 pm   Post subject: (No subject)

beat ya by one min.....lol Laughing
the_short1




PostPosted: Fri Apr 23, 2004 7:23 pm   Post subject: (No subject)

how is this sposed to work anyways....
code:

elsif
    %The Wizards Abilities.
        rank = "wizard" then


shouldn't it be.,,..

elsif rank = "wizard" then
%The Wizards Abilities.

cuz urs is an incomplete if statement cuz it cuts iff afta % symbol....

yea.... CASE contruct works good... although i havn'ed used one in AGES!... i should start again..
gamer




PostPosted: Fri Apr 23, 2004 8:11 pm   Post subject: (No subject)

use case instruction instead when it'a available, since it takes up less memory so the program wont lag as much overall
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: