Changing an instance variable by

Get help using Construct 2

Post » Thu Jan 12, 2012 5:59 pm

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.

B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Thu Jan 12, 2012 6:23 pm

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.

gazoogle2012-01-12 18:47:32
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Thu Jan 12, 2012 6:38 pm

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
B
29
S
12
G
7
Posts: 740
Reputation: 7,839

Post » Thu Jan 12, 2012 6:51 pm

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...gazoogle2012-01-12 18:53:09
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Thu Jan 12, 2012 6:57 pm

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
B
84
S
12
G
9
Posts: 99
Reputation: 9,508

Post » Thu Jan 12, 2012 7:13 pm

Thanks, that seems to do exactly what I want. Seeing the cap helped (sub event).
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Thu Jan 12, 2012 7:28 pm

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
Zetar2012-01-12 19:32:16
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Thu Jan 12, 2012 7:50 pm

[QUOTE=Zetar] 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
[/QUOTE]

Thanks, that looks good too, glad to learn more about using the Sprite.UID
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Thu Jan 12, 2012 8:30 pm

@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).
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Thu Jan 12, 2012 11:04 pm

Ah yes, I will read through those. I should have looked in that post. Thanks!
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests