back to original image after random image change
miharo
Member, PRO Posts: 41
I'm new to GS, sorry if this question is too easy
I have this actor using image0
I want it to change its image randomly to image 1-5 for 2 seconds and then go back to image 0 for 2 seconds and again random 1-5 and so on...
What am I doing wrong?
Timer
For 2 seconds
Change Attribute
set self.image to "image"..random(1,5)
Timer
For 2 seconds
Change Attribute
set self.image to image0
Comments
@miharo you have to add the file extension at the end. So it should be
"image"..random(1,5)..".png"
or whatever file type it is.
Also you would be better to store the random index in a local attribute and then call the local attribute in the expression. Finally make sure you are using an expression and it is not just text in the text editor. This is a bit of a weird Gamesalad issue where you may see what looks like an expression but GS thinks its just text and visa versa.
My Latest GS Game - Tiny Spirit
My First GS Game - Dashing Ralph
thanks Stueynet
image randomly changes now... that first part is working...
problem is after 2 seconds it is not going back to original image (image0)
I am trying to make this
2 secs random
2 secs image0
2 seconds random
2 seconds image0
and so on...
uh huh i figure it out
i have to destroy and respawn the actor, thats it...
thanks for help
You shouldn't have to respawn the actor. You should be able to change the image in exactly the way you're describing.
Look at the attached behaviours and you'll see an example of how this can be accomplished (not necessarily the best way, but an easy way.)
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Alternatively, if you don't need to use the random number for any other purpose, you can avoid making the random attribute entirely:
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
thank you Armelline, this is the solution i was looking for at the first place. So helpful...
Let me ask you something, what is the downside of destroying and re-spawning the actor? (Besides it's not the right way to do it) I am curious..
In most cases there will be no particular downside. But it will use more resources than not destroying/respawning it, so in a big project there will be a tiny performance dip. Realistically, though, it's not going to be a any issue unless you're doing it lots of times with lots of actors.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
thanks for info, i appreciate it