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

Username:   Password: 
 RegisterRegister   
 lightBike help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
evildaddy911




PostPosted: Mon Nov 07, 2011 4:04 pm   Post subject: lightBike help

What is it you are trying to achieve?
basic lightbikes program


What is the problem you are having?
im having trouble adding a powerup that makes your trial longer,
the 'shift' procedure says "array subscript is out of range"


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
see below

Please specify what version of Turing you are using
4.1.1



lightbikes.t
 Description:
simple lightbikes program

Download
 Filename:  lightbikes.t
 Filesize:  3.79 KB
 Downloaded:  47 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Mon Nov 07, 2011 5:16 pm   Post subject: RE:lightBike help

Turing:

    for decreasing b : upper (y) .. 2   % moves bike trail forward
        x (b) := x (b - 1)
        y (b) := y (b - 1)
        x2 (b) := x2 (b - 1)
        y2 (b) := y2 (b - 1)
    end for


What happens when the players lightbike's trail is longer than the computers?
Eg:
y : array 1..60
y2 : array 1..50
evildaddy911




PostPosted: Mon Nov 07, 2011 5:55 pm   Post subject: Re: lightBike help

it crashes, so i changed it to
Turing:
    for decreasing b : upper (y) .. 2   % moves bike trail forward
        x (b) := x (b - 1)
        y (b) := y (b - 1)
    end for
    for decreasing m : upper (y2) .. 2
        x2 (m) := x2 (m - 1)
        y2 (m) := y2 (m - 1)
    end for


but it still crashes and points to the drawing trail part. i did the same thing to it:
Turing:
    for c : 2 .. upper (x)
        drawfilloval (x (c), y (c), 3, 3, brightblue)             % draws trails
    end for
    for n : 2 .. upper (x2)
        drawfilloval (x2 (n), y2 (n), 3, 3, brightgreen)
    end for

now it works, thanks a lot!
Zren




PostPosted: Tue Nov 08, 2011 2:04 am   Post subject: RE:lightBike help

Just so you know, there's no reason you can't use the same variable name for each of the for loops. The variable is only decalared in the scope of the loop.

Example:
Turing:

    % i hasn't been declared
    for i : 67 .. 69
        put i
    end for
    % put i would fail here as i has been unreferenced (undeclared) as it's outside the scope the variable was declared in.
    for i : 1 .. 100
         put i
    end for
    % put i would fail here as i has been unreferenced (undeclared).


That is perfectly legal code, as the variable i has been undeclared as it leaves the scope of the for loop.

A coding standard is to use i as a counter instead of a random variable name if nothing is more suitable (Eg: x, and y would be more suitable if looping over a all pixels on the screen).
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  [ 4 Posts ]
Jump to:   


Style:  
Search: