How can I make a selected image stay when the actor dies and respawn?
Before the start of the basketball game, the player can select which color of ball he wants to play with. I got the changing ability working but when the ball gets destroyed and spawn again, the ball color goes to the first original color.
here's how my ball changes colors.
When Touch is pressed and if Attribute self.image is White then Change Image to Black
When Touch is pressed and if Attribute self.image is Black then Change Image to Gray
When Touch is pressed and if Attribute self.image is Gray then Change Image to Red
When Touch is pressed and if Attribute self.image is Red then Change Image to Blue
When Touch is pressed and if Attribute self.image is Blue then Change Image to Green
So how can I make it stick to red if that's what i've selected and vice versa?
Best Answer
-
Icebox Posts: 1,485
@Dell7730 the reason why your having this problem from the begining is because your using these rules
When Touch is pressed and if Attribute self.image is White then Change Image to Black
When Touch is pressed and if Attribute self.image is Black then Change Image to Gray
When Touch is pressed and if Attribute self.image is Gray then Change Image to Red
When Touch is pressed and if Attribute self.image is Red then Change Image to Blue
When Touch is pressed and if Attribute self.image is Blue then Change Image to Greenwhen ever the ball respawns , it will respawn as its original form and then you will have to keep pressing it until to reaches the color you want. so your first color is white , it will spawn as the original color white. Instead of using this method you can do this
create a global integer attribute , call it color set it to 1
1- create a rule
if touch is pressed change game.color to game.color + 12- if you have 3 pictures for example , make 3 rules:
if game.color = 1
display image redif game.color = 2
display image blueif game.color = 3
display image green3- Now you want it to go back to 1 when it is greater than 3 cause you only have 3 images.
if game.color > 3
change attribute game.color to 1(now for many images id suggest you use tables)
so everytime it is touched it will loop through all the images , and now when you play the game even if the ball is destroyed the game.color will not change , game.color will remain the same, so if it was 2 which represents blue image , the moment the ball respawns it will pick up that it should change its image to a blue image because the value is 2.
i hope this works
Answers
@Dell Agarpo wouldnt a global attribute work ? so that it spawns and changes the color depending on a global attribute?
if game.color = 1 , change self.image to red
if game.color = 2 , change self.image to blue
etc.
so even if the actor is destroyed the global attributes will remain the same as it respawns. but since your dealing with self attributes it will just repeat the rules all over again i think.
you just gave me an idea to try, i'll let you know what happens
@Icebox1910
no it don't work
IT WORKS, THANKS!
@Dell7730 anytime , im glad it works and good luck
Here's a screen grab vid of the game showing the ball changing color
https://dropbox.com/s/bosoxvlfgerrg00/Color%20Change.mov?dl=0