Picking a Container Object From a Family

1

Stats

3,991 visits, 5,247 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 29 Sep, 2015. Last updated 19 Feb, 2019

Introduction

So recently I was making a prototype for a game I've been thinking about, and when I got to actually adding animation layering, I ran into a big problem; you can't normally pick an instance that is linked to an object in a family without making heaps of events to figure out which object in the family it is that's currently picked.

After some theorizing, I made a function to address this issue. This is a dodgy workaround, and I really hope someone figures out a better way to do this, but for now it's the best I've found.

The Issue

So I have two families.

charanim is the upper animation sprite (for attacks and other movements that don't change the whole body) and charbody is the body sprite which has an idle and walk animation for each object. The objects inside these families are in containers so that for example, king_anim will always be linked to it's king sprite. The idea here is that the body sprite is only for cosmetics, and the [name]_anim sprite does all the work, and houses all the variables.

These are the sprites I'm referencing:

The problem is, doing something like this doesn't work:

Since it doesn't know you want the container, it just picks all the instances. We don't want this from clicking on one of them.

The Good, the Bad, the Ugly

So there's the bad news. The good news is that there are workarounds for this. The ugly part is that you still can't fully automate it.

This is how I tried to do it before:

But that's just painful, confusing and spectacularly inefficient.

Now recently, as in today, I found out you can just use a function for this and pick the charanim or charbody from the UID given from the function.

Here's what I'm using now:

And as it turns out, it works too!

The Reasoning

As it goes through the list of objects in the function, it says no to all of the objects before it that don't have the UID you put in. When it's ignored all those and has reached one it identifies as itself, it has now picked an instance of the object with the container, so it has also picked the other object in the container. It then gives back that UID of the other object. When you pick the member of the family with the UID given from the function, you get what is essentially the member of the second family that is in the container of the member of the first family.

Limitations

There are many.

The most obvious is that it is not automated. You have to put in two events for each object for it to work. Unfortunately there doesn't seem to be any easy way of dealing with this.

The second most obvious is that if you want more container objects, you have to add events for every situation you need. If I had 5 families, I would need 25 events per object. Luckily, this doesn't really happen that often.

If you have heaps of objects in heaps of families, you're in a world o' hurt, and not even the gods can save you.

The other problem is that picking instances is a bit tricky. Most of the time, a for each loop is needed for blanket events like this one:

Another Note

Just on a side note; it is possible to play and detect animations with variables. This means you could technically just have one sprite object for every character in the game, give that object a string variable called "name" or something, and then when you change animation, you add that as a prefix; "set animation (self.name&"_[animation name here]")"

The problem is, this makes developing the game really nasty, since you now have to name your characters correctly and then change their start animation so you know what they are. I don't like that kind of thing.

All the best,

Sumy

Edit

A much easier way is to just give one of the families a variable housing the other family's UID. Pretty sure this can be done at runtime start without events. -_-

  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!