Computer Science Canada

Error: Cannot allocate item. Out of id numbers (max 1000)

Author:  Kactus [ Sat Apr 15, 2006 12:31 am ]
Post subject:  Error: Cannot allocate item. Out of id numbers (max 1000)

So ive turned the moving dot tutorial into a simple program with a picture instead of a dot a BG and while I am playing it i get this Error: Cannot allocate item. Out of id numbers (max 1000) can anyone help?

here is the code:

code:
View.Set ("offscreenonly")
colorback (white)

var bg : int := Pic.FileNew ("BG.bmp")
var obj1 : int := Pic.FileNew ("bush.bmp")
var sprite : int := Pic.FileNew ("Marioright.bmp")
var x, y : int
var chars : array char of boolean

x := 10
y := 46

loop
    Pic.Draw (bg, 0, 0, 0)
    Input.KeyDown (chars)

   % if chars (KEY_UP_ARROW) and y < maxy - 30 then
    %   y := y + 1
   % end if
    if chars (KEY_RIGHT_ARROW) and x < maxx - 10 then
        x := x + 1
        sprite := Pic.FileNew ("Marioright.bmp")
    end if
    if chars (KEY_LEFT_ARROW) and x > 10 then
        x := x - 1
        sprite := Pic.FileNew ("Marioleft.bmp")
    end if
    if chars (KEY_DOWN_ARROW) and y > 46 then
        y := y - 1
    end if

    Pic.Draw (sprite, x, y, picMerge)
    Pic.Draw (obj1, 80, 46, picMerge)
    delay (10)
    View.Update
    cls

end loop

Author:  [Gandalf] [ Sat Apr 15, 2006 2:49 am ]
Post subject: 

That's because you're allocating a new picture at each iteration of your loop with Pic.FileNew(). What you should be doing is loading all your neccessary pictures at the start of the program (as you have done with Marioright.bmp) and then just changing which picture is being drawn inside the loop. What I suggest you do is have a variable which holds the last directional key pressed, and draw the picture based on that variable.

Author:  Kactus [ Sat Apr 15, 2006 1:24 pm ]
Post subject: 

it worked! thank you


: