Changing an instance variable by

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply
Author
3,476 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Topic: Changing an instance variable by
    Posted: 12 Jan 2012 at 5:59pm
What I want to do is change an instance variable of one instance of an object when I click on a second or different instance of that object.

Back to Top
3,476 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 6:23pm
Maybe I should clarify what I want to do a bit more.

I click on sprite 1 - it "lights up"
I click on a different instance of sprite 1 - it "turns off" the original sprite.



Edited by gazoogle - 12 Jan 2012 at 6:47pm
Back to Top
5,380 Rep
Post Options Post Options   Quote smitchell Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 6:38pm
If you have a boolean for each sprite, then have a event like:
- the booolean im refering to is: IsOn for this example

Mouse.OnObjectClicked(Sprite1)
Sprite1.isIsOn
     -> Do what you want here for Sprite1

Mouse.OnObjectClicked(Sprite2)
Sprite2.isIsOn
     -> Do what you want here for Sprite2
In memory of flash :'(
Back to Top
3,476 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 6:51pm
What I have is about 100 blocks. I click on a block and it changes that block by changing the opacity, and it turns on its instance variable and a global variable. If I click on a different block, I want to make the original block go back to its original state.

All the blocks can go to their start-up state as well, if that helps...

Edited by gazoogle - 12 Jan 2012 at 6:53pm
Back to Top
5,267 Rep
Post Options Post Options   Quote onzephyr Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 6:57pm
Don't know if this fits the bill perfect but it's the first idea that came to mind from your original post.

in short.
on click sprite.
Turn off all sprites
Turn on the one clicked.

example .capx
Back to Top
3,476 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 7:13pm
Thanks, that seems to do exactly what I want. Seeing the cap helped (sub event).
Back to Top
8,058 Rep
Post Options Post Options   Quote Zetar Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 7:28pm
Another way would be to make a global variable "TurnedOn".

Startup
-> Set "TurnedOn" to Sprite.UID //You can use an instance ID to select which one...

Mouse.On click Sprite
->Set "TurnedOn" to Sprite.UID

Every Tick
->Sprite Pick UID="TurnedOn"
-->Sprite Play LightUp animation

Then set up so any other time it plays the default animation


Edited by Zetar - 12 Jan 2012 at 7:32pm
Try HEX'N AROUND in the C2 Arcade!
Back to Top
3,476 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 7:50pm
Originally posted by Zetar Zetar wrote:

Another way would be to make a global variable "TurnedOn".

Startup
-> Set "TurnedOn" to Sprite.UID //You can use an instance ID to select which one...

Mouse.On click Sprite
->Set "TurnedOn" to Sprite.UID

Every Tick
->Sprite Pick UID="TurnedOn"
-->Sprite Play LightUp animation

Then set up so any other time it plays the default animation


Thanks, that looks good too, glad to learn more about using the Sprite.UID
Back to Top

Moderator
30,821 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 8:30pm
@gazoogle: you might profit frome checking out the "Picking/selecting instance(s)" section in the how do I FAQ.

There are a few examples (the "Understand how to use instance variables to pick specific objects " topic is really a nice read imo).
Back to Top
3,476 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Posted: 12 Jan 2012 at 11:04pm
Ah yes, I will read through those. I should have looked in that post. Thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down