Computer Science Canada

Cannot allocate item error (pleas help me!!!!)

Author:  Bored [ Wed Jan 05, 2005 4:39 pm ]
Post subject:  Cannot allocate item error (pleas help me!!!!)

I'm wroking On a project for computer sciences, an online Tag game, and i'm starting with player movement. The only problem is the game keeps crashing on me and says "Cannot allocate item. Out of id numbers (max 1000.)". Heres the code in it's present siMple state.
code:
setscreen ("graphics:600;600,offscreenonly")
var speed, angle : int
var x, y: real
var chars : array char of boolean
var pic := Pic.FileNew ("darkball2.bmp")
var plr := pic
speed := 3
angle := 0
x := 0
y := 0
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y := y + speed * cosd (angle)
        x := x - speed * sind (angle)
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - speed * cosd (angle)
        x := x + speed * sind (angle)
    end if
    if chars (KEY_RIGHT_ARROW) then
        angle := angle - speed
    end if
    if chars (KEY_LEFT_ARROW) then
        angle := angle + speed
    end if
    if x > maxx - 20 then
        x := maxx - 20
    end if
    if y > maxy - 20 then
        y := maxy - 20
    end if
    if x < 0 then
        x := 0
    end if
    if y < 0 then
        y := 0
    end if
    if angle > 360 then
        angle := angle - 360
    end if
    cls
    plr := Pic.Rotate (pic, angle, 10, 10)
    Pic.Draw (plr, round (x), round (y), picMerge)
    View.Update
end loop

please somone can you finout what's wrong and tell me. I don't understand the error.
p.s. i've attached the graphic to this post

Author:  Cervantes [ Wed Jan 05, 2005 4:59 pm ]
Post subject: 

Try making an array of pictures from 0 to 35 to store rotated pictures. Make this array and initialize it outside of your loop. I believe the problem is that you are rotating the picture so many times inside the loop and Turing cannot handle more than 1000 pictures being assigned to variables. So, when you reach the 1000th execution of the loop, the program crashes.
Check Asian's tutorial on rotation and movement to see how to do that bit with the array.

Author:  Neo [ Wed Jan 05, 2005 5:03 pm ]
Post subject: 

Or you can simply stick the below code before View.Update. It will free your pics after they have been used. Adding a delay wouldn't hurt either.
code:

 Pic.Free (plr)

Author:  Bored [ Wed Jan 05, 2005 5:18 pm ]
Post subject: 

Neo wrote:
Or you can simply stick the below code before View.Update. It will free your pics after they have been used. Adding a delay wouldn't hurt either.
code:

 Pic.Free (plr)

thanks neo that worked. I had tried using Pic.Free before but it didn't work because i had used it befor plr:=Pic.Rotate and it didn't work but it works if you put it after view.update. And also the reason there's no dely is cause i'm dESigning it with the option to choose a speed between 1 and 5 and the delay would make 1 too slow.

Author:  Cervantes [ Wed Jan 05, 2005 5:30 pm ]
Post subject: 

Neo wrote:
Or you can simply stick the below code before View.Update. It will free your pics after they have been used. Adding a delay wouldn't hurt either.
code:

 Pic.Free (plr)

I wouldn't recommend doing that. If you have a fast computer, the program may work fine right now, but as you make it more and more complex, the program will run slower and slower. Pic.Rotate takes a fair amount of cpu time, so creating the pictures outside the loop will make your program run faster. It's worth the effort. Besides, you learn something new, by doing it this way 8)


: