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

Username:   Password: 
 RegisterRegister   
 max id error with sprites... CONTINUED
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
programmer_needs_help




PostPosted: Thu Jun 08, 2017 4:55 pm   Post subject: max id error with sprites... CONTINUED

So i'm making a sword fighting game in turing and after repeated use of the attack button an error occurs and the game crashes. It's a max ID error i think becuase each time the player attacks the sprite image is replaced. If you have a suggestion can you please write the code? I'm kind of new to sprites and stuff. Thank You Smile

The following is the code snippet:

% Sword Attack
elsif arrowInput (' ') and playerYValue <= ground then
player := Pic.FileNew ("playerBlazeSword.bmp")
player := Pic.Scale (player, 152, 165)
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)
View.Update
player := Pic.FileNew ("playerBlaze.bmp")
player := Pic.Scale (player, 152, 165)
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)

plsyerBlazeSword.bmp is the character picture with a sword

playerBlaze is a regular picture of the player
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Jun 08, 2017 5:57 pm   Post subject: RE:max id error with sprites... CONTINUED

Are you sure it's an illegal sprite ID and not an illegal picture ID? You need to use Pic.Free to delete unnecessary images from memory before you can re-assign the variable.

If you aren't using more than a thousand pictures, you might as well load all of them and give them all unique variables at the beginning of the game. Then you only need to use Sprite.ChangePic to swap, no need for Pic.FileNew.

Also, look into Sprite.Animate. it combines all your standard sprite functions into a single line.
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:06 pm   Post subject: RE:max id error with sprites... CONTINUED

Process "playerMovement": Cannot allocate item. Out of id numbers (max 1000)

is the error message
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:08 pm   Post subject: RE:max id error with sprites... CONTINUED

i don't understand what you mean by "You need to use Pic.Free to delete unnecessary images from memory before you can re-assign the variable." Can you show me where to put that? I tried it before.
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:28 pm   Post subject: RE:max id error with sprites... CONTINUED

omg I fixed it thanks so much!!!!! Your advice worked
Insectoid




PostPosted: Thu Jun 08, 2017 6:30 pm   Post subject: RE:max id error with sprites... CONTINUED

You are only allowed to create 1000 images in Turing for technical reasons. Any time you call Pic.FileNew or Pic.Scale, a new image is created. If you're doing that in a loop, it doesn't take long to reach 1000. To get around this, you need to use Pic.Free to delete the pictures you're done using. Deleted pictures no longer count towards the 1000 picture limit.

In your example, you'll need an extra variable. We'll call it 'rawImage', because it will hold the unscaled image.

RawImage := Pic.FileNew ("blah.bmp")
Player := Pic.Scale (RawImage)
Pic.Free (RawImage)

Now, before you chance player to a new image later, you need to free it too:

Pic.free (player)
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:30 pm   Post subject: RE:max id error with sprites... CONTINUED

wait never mind its till crashing

I did this:

elsif arrowInput (' ') and playerYValue <= ground then
Sprite.ChangePic (playerSprite, playerAttack)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)
View.Update
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:31 pm   Post subject: RE:max id error with sprites... CONTINUED

ill try what u just said
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Jun 08, 2017 6:31 pm   Post subject: RE:max id error with sprites... CONTINUED

What is the error message?
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:33 pm   Post subject: RE:max id error with sprites... CONTINUED

Process "playerMovement": Cannot allocate item. Out of id numbers (max 1000)

is the error message
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:34 pm   Post subject: RE:max id error with sprites... CONTINUED

I tried Pic.Free:

Sprite.ChangePic (playerSprite, playerAttack)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)
View.Update
Pic.Free (player)
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)

now it says:
Process "playerMovement": Pic was freed
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:35 pm   Post subject: RE:max id error with sprites... CONTINUED

If you're wondering, all this code is in the playerMovement process
Insectoid




PostPosted: Thu Jun 08, 2017 6:38 pm   Post subject: RE:max id error with sprites... CONTINUED

You have to free the image after you are done with it. Freeing the image deletes it from memory, which means you cannot use it anymore. You can't draw it and you can't assign it to a sprite.

So tell me why you are freeing an image immediately before assigning it to a sprite?
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:41 pm   Post subject: RE:max id error with sprites... CONTINUED

Ok I understand. Now here:

elsif arrowInput (' ') and playerYValue <= ground then
Sprite.ChangePic (playerSprite, playerAttack)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)
View.Update
Sprite.Free (playerAttack)
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)

I'm not using the playerAttack image anymore, yet it still crashes.
programmer_needs_help




PostPosted: Thu Jun 08, 2017 6:43 pm   Post subject: RE:max id error with sprites... CONTINUED

Same thing happens when I free the pic at the END:

elsif arrowInput (' ') and playerYValue <= ground then
Sprite.ChangePic (playerSprite, playerAttack)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
delay (20)
View.Update
Sprite.Free (playerAttack)
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
Pic.Free (playerAttack)
delay (20)
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 3  [ 39 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: