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 Studio Chat / [SOLVED] playsprite issues within a "for i" loop

Author
Message
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 22nd Oct 2021 19:03
within my code i have a new alien being created each level and added to my alien.length. my issue is that my first alien created works with the movement and setting the animation, any after that are created move but do not play the animation for the 'climb' case. All aliens move and animate correctly if nto in the "climb" state.

note that this code was added after and is the only way ive gotten the animation to work correctly and i shouldnt need it

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

Go to answer

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 22nd Oct 2021 22:36
Not sure, but if all aliens work fine except the climb then I'd say the below line is the cause



are you sure alienb[i].state_now = 'climb' is being set?

care to take a screen shot and illustrate what is road[0]?
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd Oct 2021 01:00
Quote: "
are you sure alienb[i].state_now = 'climb' is being set?
"

yes the state_now and last_state are working i tested those.... literally every other part of it is working except the code below for anything except the first alien spawned within the array (alienb[0].id)
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Oct 2021 02:56 Edited at: 23rd Oct 2021 03:10
doubt it's helpful but i can't say i've ever seen single ' strings (vs ").

thought i was onto something, but

...does print "climb"

beyond that, are you sure the first/last anim frames are correct? aka:

the first frame for climb really is the last frame for atk (28), et al?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 23rd Oct 2021 03:00
ok, well typically speaking when a well used function fails 99.99% of the time its programmer error, PlaySprite is a very well used function probably in every project everyone makes, it it had a bug we would know about it

So the first port of call is to backtrack and find a reason for it failing, I have looked over your function a few times and the only place I can see 'climb' being set is on that line and without more information its hard to bug track

it is odd that the first sprite works but subsequent sprites fail

Put a log command in that case and run in debug

Log("climb state set")

check the console output, but I don't think the problem is in that case I am pretty sure its in the block above

Change the < to a <= just in case the y is perfectly aligned, if both y are the same this line will fail

if alienb[i].y <= getspritey(road[0].id)-120 and alienb[i].oldx <> alienb[i].x







Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 23rd Oct 2021 03:05
Quote: " i've ever seen single ' strings (vs ")."


its a common thing across languages and can alleviate the need for escaping double quotes inside strings "this 'string' has quotes" v's "this \"string\" has quotes"<< for example, very handy in Javascript and PHP
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd Oct 2021 06:07 Edited at: 23rd Oct 2021 06:14
so i thought it was the first alien spawned that keeps playing turns out its the last alien spawned in that plays mostly. i found that if i keep advancing levels (spawning more in) sometimes more than one will animate and on a very rare chance ive got all to play without editing the code
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 23rd Oct 2021 10:41
Did you try "Change the < to a <="?
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd Oct 2021 16:12 Edited at: 24th Oct 2021 04:43
This post has been marked by the post author as the answer.
Quote: "Did you try "Change the < to a <="?"

yes i have made those changes with no luck
Quote: "the first frame for climb really is the last frame for atk (28), et al?"

i had my frame count wrong thanks for pointing this out
there is another function to check if the alien is dead and if it is it falls to the top of the road. when they die there is a timer (decay timer) but just like with the climbing animation, it mostly works for the last alien spawned in. the others seem to skip the decay timer and falling part.

Edit: thanks for the help and while i found a few other issues my main problem was that i had no state for when the aliens were dead. there was a stop sprite playing when they died but no state change so it kept it in whatever state it died in
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 24th Oct 2021 17:07
I love those Eureka moments, glad you found the issue, I knew it had to be a state thing but without seeing the entire code chain its next to impossible to accurately diagnose.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Oct 2021 18:21
Quote: "its a common thing across languages and can alleviate the need for escaping double quotes inside strings "this 'string' has quotes" v's "this \"string\" has quotes"<< for example, very handy in Javascript and PHP"


There is a functional difference in PHP between single and double quotes.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Oct 2021 18:45
Glad you solved your issue. But consider managing your animations differently. Below is how I've set them up in one of my games. Frames are specified in one easy to see and understand location. The animation being played is also easier to understand.


Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 24th Oct 2021 19:12
Quote: "There is a functional difference in PHP between single and double quotes."


Yes, depending if you want automatic parsing of $variables inside strings.

Quote: "Below is how I've set them up in one of my games."


That's nice and clean, I like it

I setup a sprite management and animation system for a game engine I am building in Love2D, 3 scripts and 400 lines of code later and I can create, move and animate a sprite.... AppGameKit really takes the pain out of setting up basic systems!
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 24th Oct 2021 19:17
Quote: "Below is how I've set them up in one of my games. Frames are specified in one easy to see and understand location. The animation being played is also easier to understand."

that looks a lot better, i will for sure being using this sertup
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Oct 2021 21:19 Edited at: 24th Oct 2021 21:21
Quote: "AppGameKit really takes the pain out of setting up basic systems!"


In my barbarian game, I wrote all my own animation and timing routines. I'm sure I had a pretty good reason for doing it at the time, but I don't recall what it was now lol. It probably makes up half the code of the overall game

Btw, the seesaw flag controls whether the animation is one way or goes back and forth. Like a sequence might be 3,4,5,6,5,4,
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 25th Oct 2021 01:25
Not sure I see any reason to rewrite the wheel with AppGameKit and write an animation system that must have been a pretty severe edge case, but that being said its a good learning experience, Love2D and RayLib have no such sprite systems you can load and draw an image so creating a AppGameKit style sprite system in both was very educational (C++ for RayLib as C has no classes and meta tables in Lua to spoof class behaviour) both actually turned out very well but still undecided what one I am going to stick with, I always seem to come back to AppGameKit for some mad loyalist reason.

Quote: "Like a sequence might be 3,4,5,6,5,4"


Handy for basic walk/run cycles and jump animations, I like that idea too, think I'll steal that one
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee

Login to post a reply

Server time is: 2024-04-25 15:05:29
Your offset time is: 2024-04-25 15:05:29