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 Previous  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 6:48 pm   Post subject: RE:max id error with sprites... CONTINUED

In the above 2 comments, program crashes after first button press
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




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

Are you really done with it at the end of the function? What if you call the function again? The second line uses that image after all.
programmer_needs_help




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

Well, if its in a loop and I need to call it on command of the user, won't I always need it in memory?
programmer_needs_help




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

How could I get rid of it if the user can use it throughout the whole game?
Insectoid




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

Yup. So if the problem is that you're loading images in a loop, why don't you move the code that loads it out of the loop? If it's not in a loop, then it only happens once, and if it only happens once, you won't hit 1000 images. If you don't hit 1000 images, you don't need to free them.
programmer_needs_help




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

what if i declare it in a separate process without a loop, and then fork it?
programmer_needs_help




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

Because if I do this outside a loop, it'll only work one time. Won't it?
programmer_needs_help




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

I tried this:

process thing
Sprite.ChangePic (playerSprite, playerAttack)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)

View.Update
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
end thing

elsif arrowInput (' ') and playerYValue <= ground then
fork thing

It doesn't seem to crash but there's lag! Sad
Sponsor
Sponsor
Sponsor
sponsor
programmer_needs_help




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

There's also an "end thing" line, i just forgot to copy it. Should look like this:

process thing
Sprite.ChangePic (playerSprite, playerAttack)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)

View.Update
Sprite.ChangePic (playerSprite, player)
Sprite.SetPosition (playerSprite, playerXValue, playerYValue, true)
end thing

elsif arrowInput (' ') and playerYValue <= ground then
fork thing
Insectoid




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

Uh, the fewer processes you use, the better. Ideally zero. Use procedures instead. It will save you a lot of problems down the road.

Once you load a picture, you can use it as many times as you want. You can draw it ten times, you can have ten different sprites use it, etc.

However, if you declare it inside a procedure or process, it can only be used inside that process, so don't do that.
programmer_needs_help




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

If i don't use a process or a procedure, how can i reference that code outside of a loop? I'm so confused
Insectoid




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

Why do you think you need a process or procedure to access a variable?
programmer_needs_help




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

Well... You said to do this attack sprite/picture changing outside of the loop. The only thing which I know that can do that yet still be able to reference it is through a process or procedure. And i use the process so i can move multiple things on the screen at once.
Insectoid




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

I said load the picture outside of the loop. That's only two lives: Pic.FileNew and Pic.Scale. attaching it to a sprite happens after the picture is loaded.
programmer_needs_help




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

So I can attatch it to the sprite in the loop?
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 2 of 3  [ 39 Posts ]
Goto page Previous  1, 2, 3  Next
Jump to:   


Style:  
Search: