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

Username:   Password: 
 RegisterRegister   
 Array Subscript Is Out Of Range?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Weapon X




PostPosted: Wed Apr 27, 2005 11:53 am   Post subject: Array Subscript Is Out Of Range?

code:

setscreen ("offscreenonly")
var score1, score2, ballx, ballx2, bally, bally2, xmod, xmod2, ymod, ymod2 : int
var chars : array char of boolean
var chars2 : array char of boolean
var slimex, slimey, slimex2, slimey2, vy, vy2 : real
slimex := maxx / 2
slimey := 20
slimex2 := maxx / 2
slimey := 20
vy := 0
vy2 := 2
const jumpVelocity := 5
const speedX := 2  %speed of horizontal movement
const gravity := 0.15
var inAir := false
const jumpVelocity2 := 5
const speedX2 := 2  %speed of horizontal movement
const gravity2 := 0.15
var inAir2 := false
ballx := 320
bally := 0
xmod := 1
ymod := 1
xmod2 := 1
ymod2 := 1
score1 := 0
score2 := 0

loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and not inAir then
        vy := jumpVelocity
        inAir := true
    end if
    if inAir then
        slimey += vy
        vy -= gravity
        if slimey <= 10 then
            inAir := false
            vy := 0
        end if
    end if
    if chars (KEY_RIGHT_ARROW) then
        slimex += 10
    end if
    if chars (KEY_LEFT_ARROW) then
        slimex -= 10
    end if
    Input.KeyDown (chars2)
    if chars2 ("w") and not inAir2 then
        vy2 := jumpVelocity2
        inAir2 := true
    end if
    if inAir2 then
        slimey2 += vy2
        vy2 -= gravity2
        if slimey2 <= 10 then
            inAir2 := false
            vy2 := 0
        end if
    end if
    if chars2 ("d") then
        slimex2 += 10
    end if
    if chars2 ("a") then
        slimex2 -= 10
    end if
   
    View.Update

    delay (0)



drawfillbox (0, 0, maxx, maxy, 0)
drawfillarc (round (slimex), round (slimey), -50, -50, 180, 0, blue)
drawfillarc (round (slimex2), round (slimey2), -50, -50, 180, 0, blue)
drawline (0, 126, 107, 126, blue)     %|net 1 top
drawline (0, 125, 100, 125, black)     %|
drawline (0, 124, 100, 124, black)     %|
drawline (0, 123, 100, 123, black)     %|
drawline (0, 122, 100, 122, black)     %|net 1
drawline (0, 121, 100, 121, black)     %|
drawline (0, 120, 100, 120, black)     %|
drawline (0, 119, 100, 119, black)     %|
%____________________________________________

drawline (100, 0, 100, 125, black)     %|net 1
drawline (101, 0, 101, 125, black)     %|net 1
drawline (102, 0, 102, 125, black)     %|net 1
drawline (103, 0, 103, 125, black)     %|net 1
drawline (104, 0, 104, 125, black)     %|net 1
drawline (105, 0, 105, 125, black)     %|net 1
drawline (106, 0, 106, 125, black)     %|net 1
drawline (107, 0, 107, 125, black)     %|net 1
%____________________________________________

drawline (0, 110, 100, 110, black)     %|net 1
drawline (0, 100, 100, 100, black)     %|net 1
drawline (0, 90, 100, 90, black)     %|net 1
drawline (0, 80, 100, 80, black)     %|net 1
drawline (0, 70, 100, 70, black)     %|net 1
drawline (0, 60, 100, 60, black)     %|net 1
drawline (0, 50, 100, 50, black)     %|net 1
drawline (0, 40, 100, 40, black)     %|net 1
drawline (0, 30, 100, 30, black)     %|net 1
drawline (0, 20, 100, 20, black)     %|net 1
drawline (0, 10, 100, 10, black)     %|net 1

%____________________________________________

drawline (90, 0, 90, 119, black)     %|net 1
drawline (80, 0, 80, 119, black)     %|net 1
drawline (70, 0, 70, 119, black)     %|net 1
drawline (60, 0, 60, 119, black)     %|net 1
drawline (40, 0, 40, 119, black)     %|net 1
drawline (50, 0, 50, 119, red)     %|net 1
drawline (28, 0, 28, 119, blue)     %|net 1
drawline (20, 0, 20, 119, black)     %|net 1
drawline (10, 0, 10, 119, black)     %|net 1

%______________________________END OF NET 1________________________________________________________________________________________________

drawline (640, 126, 534, 126, blue)     %|net 2 top
drawline (640, 125, 540, 125, black)     %|net 2
drawline (640, 124, 540, 124, black)     %|net 2
drawline (640, 123, 540, 123, black)     %|net 2
drawline (640, 122, 540, 122, black)     %|net 2
drawline (640, 121, 540, 121, black)     %|net 2
drawline (640, 120, 540, 120, black)     %|net 2
drawline (640, 119, 540, 119, black)     %|net 2
%____________________________________________

drawline (541, 0, 541, 125, black)     %|net 2
drawline (540, 0, 540, 125, black)     %|net 2
drawline (539, 0, 539, 125, black)     %|net 2
drawline (538, 0, 538, 125, black)     %|net 2
drawline (537, 0, 537, 125, black)     %|net 2
drawline (536, 0, 536, 125, black)     %|net 2
drawline (535, 0, 535, 125, black)     %|net 2
drawline (534, 0, 534, 125, black)     %|net 2

%____________________________________________

drawline (640, 110, 540, 110, black)     %|net 2
drawline (640, 100, 540, 100, black)     %|net 2
drawline (640, 90, 540, 90, black)     %|net 2
drawline (640, 80, 540, 80, black)     %|net 2
drawline (640, 70, 540, 70, black)     %|net 2
drawline (640, 60, 540, 60, black)     %|net 2
drawline (640, 50, 540, 50, black)     %|net 2
drawline (640, 40, 540, 40, black)     %|net 2
drawline (640, 30, 540, 30, black)     %|net 2
drawline (640, 20, 540, 20, black)     %|net 2
drawline (640, 10, 540, 10, black)     %|net 2

%____________________________________________

drawline (550, 0, 550, 125, black)     %|net 2
drawline (560, 0, 560, 125, black)     %|net 2
drawline (570, 0, 570, 125, black)     %|net 2
drawline (580, 0, 580, 125, black)     %|net 2
drawline (590, 0, 590, 125, black)     %|net 2
drawline (600, 0, 600, 119, green)     %|net 2
drawline (610, 0, 610, 125, blue)     %|net 2
drawline (620, 0, 620, 125, black)     %|net 2
drawline (630, 0, 630, 125, black)     %|net 2

%_________________________________END OF NET 2_____________________________________________________________________________________________

Draw.FillOval (ballx, bally, 10, 10, 12)

ballx += xmod
bally += ymod
if ballx >= maxx then
    xmod := -xmod
elsif ballx <= 0 then
    xmod := -xmod
end if
if bally >= maxy then
    ymod := -ymod
elsif bally <= 0 then
    ymod := -ymod
end if
if whatdotcolour (ballx + 11, bally) = blue or whatdotcolour (ballx - 11, bally) = 1 then
    xmod := -xmod
end if
if whatdotcolour (ballx, bally + 11) = blue or whatdotcolour (ballx, bally - 11) = 1 then
    ymod := -ymod
end if
if whatdotcolour (ballx, bally + 11) = red then
    score1 += 1
end if
if whatdotcolour (ballx + 11, bally) = red then
    score1 += 1
end if
if whatdotcolour (ballx, bally + 11) = green then
    score2 += 1
end if
if whatdotcolour (ballx + 11, bally) = green then
    score2 += 1
end if

if score1 <= 1 then
    locatexy (0, 400)
    put "", score1, ""
elsif score1 >= 1 then
    locatexy (0, 400)
    put "", score1, ""
end if
if score2 <= 1 then
    locatexy (0, 300)
    put "", score1, ""
elsif score2 >= 1 then
    locatexy (0, 300)
    put "", score2, ""
end if

View.Update


end loop

ok so that is my code but when i run the game doesnt run. 1) can some one tell me what Array Subscript Is Out Of Range means and 2) how can i fix the problem?
(i m a noob at this whole turing thing so i m srry if i m asking stupid questions Very Happy)
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Wed Apr 27, 2005 1:31 pm   Post subject: (No subject)

It says it's out of range, because your using the wrong quotation marks.
its ' instead of "
code:

 if chars2 ('d') then

You forgot the 2 after slimey, its needs to be slimey2
code:
slimex := maxx / 2
slimey := 20
slimex2 := maxx / 2
slimey := 20

Looking good so far though. But you may want to make your slimes smaller, and your x-length of the screen longer.
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: