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.

DarkBASIC Professional Discussion / "Sprite number must be greater than 0" Error

Author
Message
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 20th Jun 2011 17:48
I'm using the following code to find a random, unused sprite number and then assign it to the sprite. I'm getting the "Sprite number must be grater than 0" error every now and then but can't figure out why. Your help is much appreciated!


Picks a random number, checking to make sure it isn't already a sprite.



Uses var_InstanceID as the sprite number when creating it.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Jun 2011 18:23
The error message is a little misleading. You get that error message if the value you provide is less than 1, or greater than 22000000 (I checked the source code).

Just change the number 499999999 to 21999999 instead.

Alternatively, you can use the FIND FREE SPRITE function provided in my plug-ins.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 20th Jun 2011 18:28 Edited at: 20th Jun 2011 18:31
The random number you're picking is way too big. Remove two 9's from it and it'll work fine.

IanM has a command called FIND FREE SPRITE() that works just the same but it's range is limited between 1 to 131,072. Your code works with 5,000,000 but I trust IanM didn't limit that range on a whim. He knows more about Darkbasic Pro than we'll ever know.

If you want to try that command out and you have yet to get Matrix 1 Utilities Plugin then wait no more... here is a direct download to the promised land of programming.

https://forumfiles.thegamecreators.com/download/2192430

Edit: Ah there he is! He beat me.

Edit Again: Looks like my help files for Matrix 1 need to be updated.

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 20th Jun 2011 22:02 Edited at: 20th Jun 2011 22:04
"Just change the number 499999999 to 21999999 instead.", holy crap! How many sprites are you using lol? Those are extremely large numbers! Perhaps you are making some virtual world but only with sprites .

http://s6.bitefight.org/c.php?uid=103081
Alaror
15
Years of Service
User Offline
Joined: 9th May 2011
Location:
Posted: 21st Jun 2011 05:39
Awesome, thanks guys!

@DVader Haha I know, it's *a lot* of sprites. My game worlds will be comprised of individual blocks which can be interacted with, so I need a sprite for each. Right now I'm just setting it at such a high number since I've still to figure out a lot of the details for my game, though by the time it's done it will almost definitely be lowered.

Login to post a reply

Server time is: 2026-07-10 14:05:11
Your offset time is: 2026-07-10 14:05:11