Changing an instance variable by Forum Home > Construct 2 General > How do I....? |
Post Reply
|
| Author | |
Post Options
Quote Reply
Topic: Changing an instance variable byPosted: 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.
|
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Options
Quote Reply
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 :'(
|
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Options
Quote Reply
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 |
|
![]() |
|
Post Options
Quote Reply
Posted: 12 Jan 2012 at 7:13pm |
|
|
Thanks, that seems to do exactly what I want. Seeing the cap helped (sub event).
|
|
![]() |
|
Post Options
Quote Reply
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!
|
|
![]() |
|
Post Options
Quote Reply
Posted: 12 Jan 2012 at 7:50pm |
|
Thanks, that looks good too, glad to learn more about using the Sprite.UID |
|
![]() |
|
Post Options
Quote Reply
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). |
|
![]() |
|
Post Options
Quote Reply
Posted: 12 Jan 2012 at 11:04pm |
|
|
Ah yes, I will read through those. I should have looked in that post. Thanks!
|
|
![]() |
|
Post Reply
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |