0 Favourites

Extract a pre-chosen object from a family

  • 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.

  • 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"

  • 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 ^^;;

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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.

  • 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?

  • 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.

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)