Extract a pre-chosen object from a family

Get help using Construct 2

Post » Mon Oct 29, 2012 4:23 pm

I read around a while on the forums but could not find what i was looking for, if its already out there im sorry.


Basicly i have a family of character-sprites that i can click on to choose to get various information from that gets stored in global variables. Then i have a confirm button that locks the variables and goes to the next layout.

But then i want to be able to spawn that already chosen characters sprite again without having to make an event saying

"
If ChosenCharacter == 1 then spawn spriteA.png
If ChosenCharacter == 2 then spawn spriteB.png
If ChosenCharacter == 3 then spawn spriteC.png
If ChosenCharacter == 4 then spawn spriteD.png
...
"

So what im wondering is if there's a way to make something in terms of

"
Spawn the family-object that has family-variable 'chosen == true'
"

Since i can for example easily make that change to the last object i clicked on earlier, but i cant really think of a way to extract the information in a spawn-object event that targets a family.

No matter how i try to go around it, it spawns a random object from the family. Any hints are appreciated.
B
7
S
1
Posts: 21
Reputation: 1,242

Post » Mon Oct 29, 2012 6:17 pm

I don't think it's possible..
But if all of your character animations were contained within one object, it would be.
A little awkward though... but once you've set it up, and if you name your animations correctly, you can set them like this:

+If character is moving right
->set animation to Character.Name&"Right"
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Mon Oct 29, 2012 6:29 pm

If it was that easy it would be nice, but the list of characters extends quite a bit, so if what i mentioned isnt possible, then i'll just have to do some extreme if-else-ing ^^;;
B
7
S
1
Posts: 21
Reputation: 1,242

Post » Tue Oct 30, 2012 12:10 am

It is that easy, it's how I'm doing the character animations in the game i'm working on.. Although I've only animated two so far, but it's pretty robust and I'd be surprised if I run into any problems down the line while adding more.

It may take a long time to put all the animations into one object but it'll be worth it for the cleaner event sheet at the end.
just my suggestion :p
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Tue Oct 30, 2012 1:54 am

Well that is fine for the sprite part, and for this particular example i think i can make great use of it to thanks ^__^

However, i sort of wanted to use it in in a more broad perspective later on, like really extracting the info from the pre-chosen character in several ways except from just the sprite ^^;

If i do it that way, it wont inherit the correct values from the chosen object :/ I tried using a "For each Family.characters" and then added the condition if Chosen == true then spawn. But for some reason nothing came out in to the playfield.
B
7
S
1
Posts: 21
Reputation: 1,242

Post » Wed Oct 31, 2012 2:16 am

Maybe im trying to use the families in a wrong way, but sometimes it works as i want to and sometimes it doesnt when using families.

"For each 'family1'" for example, does it only test the objects of the family that is out in the playing field? Maybe i have been thinking about it the wrong way, because i just assumed it tested all family objects, including ones not in the layout.
B
7
S
1
Posts: 21
Reputation: 1,242

Post » Wed Oct 31, 2012 5:21 am

Events don't ever affect objects that aren't in the layout..
Because they aren't there :p
Or do you mean if they're on screen? Because in that case it should still apply to them.

What were you hoping to do?keepee2012-10-31 05:21:52
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Wed Oct 31, 2012 4:00 pm

Im basicly a numbnut, because i was able to solve it myself with the nickname plugin (http://www.scirra.com/forum/topic57943_page1.html) and actually having pre-defined nicknames to each sprite. I was thinking backwards with assigning new nicknames to things in families and then always summon that assigned nickname. Why i was locked in that thought i dont know.

When i actually thought about the fact that i can just have all the objects or characters already nicknamed, and just summon the name of the global variable that happens to save the last clicked object, i wanted to kick myself in the nuts for thinking about this for more or less 2 days. Mostly in my head tho as i have been extremely busy.

https://dl.dropbox.com/u/15195355/chosenone.capx

The solution was so easy... if there is a solution to this without using nickname im eager to learn what i missed. Its probably equally easy.
B
7
S
1
Posts: 21
Reputation: 1,242


Return to How do I....?

Who is online

Users browsing this forum: BipolarMike, totoe and 19 guests