Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Is there a way to make this code work?

Author
Message
blueFire
13
Years of Service
User Offline
Joined: 23rd Jan 2011
Location: North Carolina
Posted: 9th Feb 2012 04:16
First the code:



When clicking on the sprite I get an error message telling me the sprite does not exist.

I have tried making both the image and sprite global but that does not work.

Jason
Canadian Mark
12
Years of Service
User Offline
Joined: 28th Jan 2012
Location:
Posted: 9th Feb 2012 04:43
Here this will work.


if you don't set the variable sprite to 0 the second loop through will throw an error
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Feb 2012 07:15
Quote: "I have tried making both the image and sprite global but that does not work."

The variables will have to be global if they are to work across multiple functions.

With AppGameKit I've learnt that it is always a good idea to check if a sprite exists (using the GetSpriteExists()) before using it in another condition.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Feb 2012 11:21
Quote: "With AppGameKit I've learnt that it is always a good idea to check if a sprite exists (using the GetSpriteExists()) before using it in another condition."

I would agree but only under certain circumstances. I wouldn't use it too often!

I like to know when a sprite exists and use arrays or other means to make sure that when I'm doing something to a sprite it exists for definite!

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 9th Feb 2012 21:45
It is time for a great debate baxslash! ....ok you win.

You are correct baxslash, I meant to say that in the nature of his functions it's a good idea...but just didn't say it.

Quote: "I like to know when a sprite exists and use arrays or other means to make sure that when I'm doing something to a sprite it exists for definite!
"

Ironically, I had my array algorithms in mind when typing that response.

blueFire
13
Years of Service
User Offline
Joined: 23rd Jan 2011
Location: North Carolina
Posted: 12th Feb 2012 03:40
After experimentation I have discovered the best way to do this is to use an array. Since arrays are global I can add the sprites to an array at the beginning then simply scroll through the array doing needed actions to the sprites later.

Jason

Login to post a reply

Server time is: 2024-11-23 04:16:49
Your offset time is: 2024-11-23 04:16:49