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

Username:   Password: 
 RegisterRegister   
 Code Skipping/Misinterpreting typing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Xarsha




PostPosted: Wed Apr 01, 2015 7:22 pm   Post subject: Code Skipping/Misinterpreting typing

I learned about Turing pretty recently and I'm making a 'choose your own adventure' game. The player is put in a situation, and has four option (a, b, c, and d) of what they want to do. The player is a wizard. They get to choose two spells at the beginning. I'm coding the spell choosing process, and I have the option for the player to ask for detail on a spell by typing 'detail [spell letter]. I then want the program to tell them the details of the spell. However, when I type any detail command, it instead acts as if I had chosen the spell I wanted detail on, and it also tells me that I entered an incorrect command, which I only want it to do if I actually enter an incorrect command, like 'cat' or '3'. Here's my code. I'm not sure what I've done wrong. Also, The actual choosing of the spell works just fine. If I type a, it gives me fireball, and the code works.

Spoiler:
Turing:
var Spell1 : string
var Spell2 : string
var Mana : int
put "Welcome to the 'Choose Your Own Adventure' Fantasy Game!"
put "In this game, you are a Wizard who is looking for the Tome of High Magic."
put "This Tome is said to contain the greatest magical secrets of the world."
put "You are jus about to set off on your adventure. You may bring a limited number of spells with you."
put "Of course, you have your trusty Migic Missile Spell, but you may bring two other spells from these:"
put "Fireball (a), Lifesteal (b), Teleport (c), and Force Object (d)."
put "Note that ou have a limited amount of mana you can use; you only have 10 mana."
put "each spell has a different mana cost."
put "If you require more information on a spell, type 'detail [letter of spell]'."
put "For example, if you wanted more information on Fireball, you would type 'detail a'."
put "Otherwise, please choose your first spell!"
loop
    get Spell1
    exit when Spell1 = "a" | Spell1 = "b" | Spell1 = "c" | Spell1 = "d"
    if Spell1 = "detail a" then
        put "Fireball: This spell creates a large explosion that deals damage to enemies. However, it has no blast force."
        put "It's radius is about 20 feet (6 metres). Be careful no to blow yourself up! This spell costs 3 mana."
        put "Now, pick your spell, or get details on another spell."
        get Spell1
    elsif Spell1 = "detail b" then
        put "Lifesteal: This spell ceates a dark link between you and a nearby ceature."
        put "You then drain the target's lifeforce, while reinvigorating yourself at the same time."
        put "While not quite as damagin as Fireball, this spell is still useful because it heals you."
        put "The range of this spell is 50 feet. This spell costs 3 mana."
        put "Now, pick your spell, or get details on another spell."
        get Spell1
    elsif Spell1 = "detail c" then
        put "Telepot: This spell causes you to quickly warp to another location."
        put "This spell activates almost instantly, so you can use it to quickly get out of danger."
        put "This spell can teleport you up to one mile away. This spell costs 2 Mana."
        put "Now, pick your spell, or get details on another spell."
        get Spell1
    elsif Spell1 = "detail d" then
        put "Force Object: This spell creates an object out of magic. The object is translucent and glows faintly yellow."
        put "You can control the object with telekinesis, and you can move it up to 50 feet away from you"
        put "You can use this spell to make meany things. For example, you could make a knife, a long pole, a ladder, or a net."
        put "This spell costs one mana."
        put "Now, pick your spell, or get details on another spell."
        get Spell1
     else
        put "You have entered an incorrect command. Please try again."
    end if
    end loop
if Spell1 = "a" then
    put "You have chosen Fireball. This spell will annihilate your enemies. What is your second spell choice?"
elsif Spell1 = "b" then
    put "You have chosen Lifesteal. This spell will drain your enemies of their energy. What is your second spell choice?"
elsif Spell1 = "c" then
    put "You have chosen Teleport. This spell will carry you to safetly and allow you to travel across many leagues. What is your second spell choice?"
elsif Spell1 = "d" then
    put "You have chosen Force object. This spell will allow to test doors, get across pits, and be the most versatile wizard in the land. What is your second spell choice?"
    get Spell1
end if
get Spell2
if Spell2 = "a" & Spell1 not= "a" then
    put "You have chosen Fireball. This spell will annihilate your enemies."
elsif Spell2 = "b" & Spell1 not= "b" then
     put "You have chosen Lifesteal. This spell will drain your enemies of their energy."
elsif Spell2 = "c" & Spell1 not= "c" then
    put "You have chosen Teleport. This spell will carry you to safetly and allow you to travel across many leagues."
elsif Spell2 = "d" & Spell1 not= "d" then
    put "You have chosen Force object. This spell will allow to test doors, get across pits, and be the most versatile wizard in the land."
    end if
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Thu Apr 02, 2015 11:55 am   Post subject: Re: Code Skipping/Misinterpreting typing

get stops at any whitespace character, which includes regular spaces. It will also not block if there are unread characters (i.e. if there are characters that are unread it will automatically read them.

So if I type "detail a" your code is going to first give spell1 the value "detail", tell you the command is invalid, then give spell1 the value "a" and tell you fireball has been chosen.

To have get read the entire line, use
Turing:
get spell1: *

If you want to know more about get I suggest looking at the documentation. It can be a bit difficult to understand at first, but once you get used to the style its actually very descriptive.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: