
-----------------------------------
evildaddy911
Mon Nov 07, 2011 4:04 pm

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



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

-----------------------------------
Zren
Mon Nov 07, 2011 5:16 pm

RE:lightBike help
-----------------------------------

    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
Mon Nov 07, 2011 5:55 pm

Re: lightBike help
-----------------------------------
it crashes, so i changed it to
    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:
    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
Tue Nov 08, 2011 2:04 am

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:

    % 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).
