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

Username:   Password: 
 RegisterRegister   
 Need a lot of help making a game!
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gnauhZ




PostPosted: Tue May 17, 2011 2:21 pm   Post subject: RE:Need a lot of help making a game!

Hey this is someone in the same group just using the same account.

I thought why not post and see if you guys can help me as well. My problem is similar to my partners but slightly easier.

Basically all i am doing is presenting options and asking the user to pick one using an array to make the choice variable *choice(1), choice(2), etc.* and I want to know if there is a more efficient way to decide what comes next besides 1000000000 if statements.

If you could give me a simple easy to understand asnswer i would forever be in your debt. Thank you, gnauhZ #2
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue May 17, 2011 2:33 pm   Post subject: RE:Need a lot of help making a game!

you could use integer variables in place of array index
code:

for i: 1..10
   if ( choice(i) ) then
      ...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
gnauhZ




PostPosted: Tue May 17, 2011 2:37 pm   Post subject: RE:Need a lot of help making a game!

I appreciate the post but that's a little vague. Just like my partner this is my first year ever programming and I am still very new at turing.

How exactly would I use integer variables?
Tony




PostPosted: Tue May 17, 2011 2:57 pm   Post subject: RE:Need a lot of help making a game!

We have various tutorials available in the Turing Tutorials forum; most common ones are linked to from The Turing Walkthrough
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
HRI




PostPosted: Tue May 17, 2011 4:45 pm   Post subject: Re: Need a lot of help making a game!

Actually I would just make a function that takes an array of choices and returns the option chosen.

Turing:

var toolChoices : array 1..4 of string := init ("Crowbar", "Wrench", "Screwdriver", "Lockpick")
var weaponChoices : array 1..3 of string := init ("Gun", "Lead Pipe", "Candlestick")
var weapon, tool : int

fcn choose (choices : array 1..* of string) : int
    var ch : string (1) := ""

    put "Here are your options: "

    for i:1..upper (choices)
        put i, ": ", choices (i)
    end for

    put "Which do you choose? "..

    loop
        getch (ch)
       
        if ord(ch) >= ord('1') and ord(ch) <= ord (intstr (upper (choices)))
        then
            result strint (ch)
        end if
    end loop
end choose

tool := choose (toolChoices)
weapon := choose (weaponChoices)

%just make an array for each choice they make


Also, let me know if that doesn't compile, I wrote it up on the spot and Turing is a real bother to use on this computer.
gnauhZ




PostPosted: Tue May 17, 2011 7:46 pm   Post subject: RE:Need a lot of help making a game!

question: is it possible to program an if statement where a variable does not equal a number
example:

if letter not= "a number"
Raknarg




PostPosted: Tue May 17, 2011 7:53 pm   Post subject: RE:Need a lot of help making a game!

So checking to see if its a number or not? I've never used it, but you should look up strintok then.
gnauhZ




PostPosted: Thu May 19, 2011 10:36 pm   Post subject: RE:Need a lot of help making a game!

Hey I just have a quick question.
My project is due tomorrow and its 11 30 where a live so a swift reply would be very much appreciated XD.

So basically I have a bunch of if statements and a bunch of procedures.

I try to run my procedures by saying "if blank = blank then
"procedure name here"

some of them work but some stop the program and give me this message saying:

"Substring index is greater than length of string"

Any ideas on how to fix this?
Also I can post my program is this doesn't make any sense just reply quickly pleaseeeeeeeee.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu May 19, 2011 10:53 pm   Post subject: RE:Need a lot of help making a game!

That means that you are trying to access a part of the string (a substring) that does not exist. E.g:

What is the 10th letter in the word "turing"?

When the program stops, it should highlight the offending line.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
gnauhZ




PostPosted: Thu May 19, 2011 10:59 pm   Post subject: RE:Need a lot of help making a game!

That confuses me though because I programmed the entire thing the same but only these last two options don't work and yet the rest of the program works... all programmed the same.

sigh. If your willing to look i'd appreciate it but if not no worries. Just post a reply if your willing to help me out cuz i'm stumped.
Tony




PostPosted: Thu May 19, 2011 11:04 pm   Post subject: RE:Need a lot of help making a game!

A good way to debug this would be to print out both the string and the index values that will be accessed, right before the line where the crash occurs. Once you know the word and the number, you could step backwards through your program to try to figure out what (and why it) happened.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
gnauhZ




PostPosted: Thu May 19, 2011 11:06 pm   Post subject: RE:Need a lot of help making a game!

Ok i'll gve it a try thanks
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 2 of 2  [ 27 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: