Changing Actor colour seems to be random? Help!

SuperDannyGSuperDannyG Member, PRO Posts: 6

Hi Guys,

New to the GS world and have hit a stumbling block that I hope you can help with :smile:

I'm trying to create an actor that when the mouse clicks on it, it changes colour.
Then if you click on it again, it changes back.

So, it starts white. If I click it, it turns black, then if I click it again, it turns white.

I've used When ALL touch is PRESSED do:
Change Attribute
Set game.SelectedTile1 To 1-game.SelectedTile1
(game.SelectedTile1 is an integer value)

Then I've got it where:
If game.SelectedTile1 = 0
Change Attribute
self.color.red=1
self.color.green=1
self.color.blue=1

Else
Change Attribute
self.color.red=0
self.color.green=0
self.color.blue=0

The good news is that it works. If I click it, it does indeed change from white to black and and back again.

However, the issue is that it seems to be random. If I click it once, nothing. Twice, nothing, third time it works. Once, nothing, twice it works; and so on.

My question is why and what am I doing wrong?

Cheers.

Comments

  • SuperDannyGSuperDannyG Member, PRO Posts: 6

    Ok, maybe it's me?

    When I click on them, they seem to randomly change colour.

    However, if I click and hold for a second, then it works every time.

    Has anyone else experienced this before?

  • SuperDannyGSuperDannyG Member, PRO Posts: 6

    Hi Guys,

    I'm having an issue with changing an Actors colour.

    What I want is to have many copies of the same actor on the screen (say 10), and if I click on one of them, then only that one changes colour (form white to black). If I click it again, it goes from black to white.

    Here's what I've done.

    I've used When ALL touch is PRESSED do:
    Change Attribute
    Set game.SelectedTile1 To 1-game.SelectedTile1
    (game.SelectedTile1 is an integer value)

    Then I've got it where:
    If game.SelectedTile1 = 0
    Change Attribute
    self.color.red=1
    self.color.green=1
    self.color.blue=1

    Else
    Change Attribute
    self.color.red=0
    self.color.green=0
    self.color.blue=0

    Now this works, but if I copy this actor 10 times and click it, they all change colour.

    How do I make it so it's independent of the others?

    I'd rather not write out 100 separate rules :smile:

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    /merged

    Please add comments to this existing thread rather than starting a new one.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    The reason they are all changing color is because you've used a rule that relies on a game attribute, the same game attribute, for all 10 copies. If you want them to independently change color, use a self attribute.

    Or for a shortcut without an extra attribute, try this:

    When touch is pressed
         Change attribute self.color.red to 1-self.color.red
         Change attribute self.color.green to 1-self.color.green
         Change attribute self.color.blue to 1-self.color.blue

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SuperDannyGSuperDannyG Member, PRO Posts: 6

    @tatiang thank you so much! That worked perfectly :smile:

    I didn't think to use a self attribute.

    And thanks for merging the threads.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You're welcome!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.