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.

Newcomers AppGameKit Corner / [SOLVED] Sprite IDs

Author
Message
stigmat
1
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 8th Jul 2020 14:12
HI all
When i do
fond =createsprite(2)
< some others line code>
player[0]=create sprite(3)

a first time, it work, cause fond get the value 10001 and player[id] the value 10002 (it seem give the values automaticatly)

but after delete all sprite and redo
fond =createsprite(2)
<some others line code>
player[0]=create sprite(3)

player[0] delete the fond sprite because both have 10001 value

if i want it work i need to pute these 2 line very near.iI have try to change myself the value doing fond=245878 , if before create sprite, create sprite change the value again for 10001 .If i do it after its weird, others sprite created before dont appear more.
Someone can help^?
THank all

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
14
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 8th Jul 2020 14:43
Stigmat, i've renamed your thread to something appropriate and moved it to the more-appropriate Newcomers board.
dandrews
User Offline
Joined: 26th Jun 2020
Location:
Posted: 8th Jul 2020 18:53
Hmm is it possible your running the same line twice after the first instance... Hard to say without the " some other code" lol
stigmat
1
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 9th Jul 2020 00:04
I dont think, i have understand a sprite id is a number after 10000 given automaticly by the app, and they must all have different nomber (for dont be the same) , then when i create player[id] it give the same number to player[id] as fond . 10001 for both . I check later again.
THank!
Bengismo
2
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 9th Jul 2020 00:14
Do you have an example project which shows your problem?

I can create multiple sprites then delete them all with DeleteAllSprites() then create them again and the sprite numbering does start at 100001 and they each have a unique id Ie 100001, 100002, 100003 etc... They dont just stay at 100001.

Are you sure it isnt just a bug in your code?
Virtual Nomad
Moderator
14
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 9th Jul 2020 00:24
I don't know what else is involved without more code from the OP, but if using 2d physics, dont forget that the walls are sprites, as well.
dandrews
User Offline
Joined: 26th Jun 2020
Location:
Posted: 9th Jul 2020 05:29
You could try printing getspriteexist and see if it's actually deleting it while running the code maybe ?
Qugurun
Valued Member
5
Years of Service
User Offline
Joined: 8th Dec 2014
Location: Tyumen, Russia
Posted: 9th Jul 2020 12:00 Edited at: 9th Jul 2020 12:11
You need to pass zero to the function, then the agc will assign the desired id to the sprite.

Bengismo
2
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 9th Jul 2020 12:19
Quote: "You need to pass zero to the function, then the agc will assign the desired id to the sprite."


That's not correct, only pass 0 to the sprite if you want a blank white image applied to it.

He was using CreateSprite(2) and createsprite(3) indicating that he had previously loaded images LoadImage(2,"Image.png") , LoadImage(3,"Image2.png")

If those images didnt exist he would get an error stating that image 2 doesnt exist and then sprite id returned is then 0....not 100001
Qugurun
Valued Member
5
Years of Service
User Offline
Joined: 8th Dec 2014
Location: Tyumen, Russia
Posted: 9th Jul 2020 13:20 Edited at: 9th Jul 2020 13:21
@Bengismo, you are right, but by my example I wanted to show something else, that you can refuse numbers and use variables. And as noted above, without a code that reproduces the error, these assumptions are all meaningless.

"DeleteSprite()" deletes the sprite correctly, it just does not reset the internal sprite counter.




Everything is working correctly. I assume that he has an error in the code.
Bengismo
2
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 9th Jul 2020 13:37 Edited at: 9th Jul 2020 13:42
Absolutely understand. I normally use the auto generated ID's and only rarely use static id numbers for any resource. I would recommend allowing AppGameKit to manage ID's, buts thats my preference. Either way works fine though. Its much more likely to be a small error in user code somewhere.

DeleteAllSprites() does start the id's at 100001 again and you are right that DeleteSprite() doesnt reset the counter and it shouldn't do so. If he is getting 100001 after recreating sprites then its likely he used the DeleteAllSprites() function to delete them all.

Quote: "without a code that reproduces the error, these assumptions are all meaningless."


This is the main point, well said. There are good ways to ask questions and bad ways which dont give a lot of information that cant be answered.

We can only use the information that was given by the original post which isnt really enough to answer the question.
stigmat
1
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 26th Jul 2020 13:05
Hi all, thank so much for your answer, yes i use deleteallsprite, when the level of the game is finish, win or not, i use deleteallsprite.
I have do a try for find when i have same ID value. and here:

test=getspriteexists(cadreperso[0])
collisiongauche[1]=clonesprite(collisiondroite[1])
if erreurok=0
erreurmsg$="creation: etait :"+str(test)+" et maintenant: "+str(getspriteexists(cadreperso[0]))+" collisiongauche[1]="+str(collisiongauche[1])+" cadreperso[1]="+str(cadreperso[0])
erreurok=1
endif

sometimes cadreperso[1] and collisiongauche[1] have different ID , and sometime the same.
Then erreurmsg$ containt : "creation: etait :0 et maintenant: 1 collisiongauche[1]=100008 cadreperso[1]=100008 (can see it display down screen on picture)

So, deleteallsprite reset all ids after 100000, if i understand its because sprite ID cant be less than 100000 value.So after that appgamekit regive value to sprite ID but must dont give same Value for 2 different ID.And here, sometime, i have these 2 sprite ID with same value.But not all time.And when its same value, i have some others weird bug.Some textid seem have same value to. (i have a text sometime appair in game for say message, and when bug, it give the rest life, like if he as same value as the original text giving the rest life).I have some bad guy sprite in the game who have collision box sprite.One left, right,up, down ... And sometime one of them disappear, i think because an other sprite as same ID value....Im still searching
Sorry for my language, i speak english like a spanish cow.
Thank again for your help!


(thank Qugurun, you make me discover "select" "case" same use as "switch" for php )

stigmat
1
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 26th Jul 2020 13:09 Edited at: 26th Jul 2020 16:19
Forget to push upload button

Attachments

Login to view attachments
stigmat
1
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 26th Jul 2020 13:23
Qugurun, i have use your code and check with replace deletesprite ... with deleteallsprite .and yes deleteallsprite reset ID value, deletesprite dont reset.i think deleteallsprite make this conflict.I have program a longer game before, without use deleteallsprite,deleting sprites in a loop (for a to ... if getspriteexists (mysprite[a]) then deletesprite(mysprite[a]) and no problem .I think my next step is change deleteallsprite by a loop and try.
Thank again!
stigmat
1
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 26th Jul 2020 13:38 Edited at: 26th Jul 2020 13:47
I have do an other try, and i see this conflict ID come when i clone a sprite from a cloned sprite randomly.If someone can try this code, and can help me for why reason they have same ID?



---> if i change deleteallsprites for deletesprite , never clonflict because never reset ID value. I think my solution is not use "deleteallsprites" more, deleteallsprite reset value ID anyway if the id sprite is already deleted, and i think its same problem with deletealltexts for text
stigmat
1
Years of Service
User Offline
Joined: 1st Apr 2019
Location:
Posted: 26th Jul 2020 14:17 Edited at: 26th Jul 2020 18:13
This post has been marked by the post author as the answer.
Im totaly missing... With this try i can see after deleteallsprite , a deleted sprite, not created exist. (It create 1 chance on 2 with random, with deleteallsprite it alway created) , with deletesprite it work normally ...



---->id dont exist, but it still have the same id value, so the system say it exist, but it not, because i think deleteallsprite reset value only when it created again, mysprite=createsprite(1) (maybe mysprite=100001), deleteallsprite (), (i think mysprite is still =100001) , mysprite=createsprite(1) (and now i think mysprite get a new value), then , when i try to know if a sprite exists, if he as be deletebefore by "deleteallsprite" , it can be an other sprite id with same value exist, deleted, but this sprite dont have same name id. I think i get it now ! (maybe its a problem when we use deleteallsprite the ID values are not already reset, but the counter)

Final solution
---->
going to still use deleteallsprite but mixed with call this function :

for all arrays need to be reset

seem workin
thank again to all

Login to post a reply

Server time is: 2020-09-27 22:10:42
Your offset time is: 2020-09-27 22:10:42