How do I add an instance with iid=0?

0 favourites
From the Asset Store
Customize the animation of character when item changed
  • I want to create an instance by pushing it onto the beginning of the instance list instead of the end. So if I have 5 instances and I add another, how do I get it so the new instance has IID = 0.

    How do I accomplish this!?

  • IID depends on wich objects you pick.

    When you pick only the last created object it has at that moment IID=0

    If you pick them all, it has the last IID.

    If you run trough them with for each (ordered) and use the IID expression + descending, it will start with the last one, and it gets IID = 0.

    IID is not an absolute, static position in the list.

    So, nope, you cant push it into the beginning of the 'instance list'.

    Well technical you can destroy all and create that one, and recreate the others.

    Yes, you can push it to the beginning of the picklist, actualy giving it IID=zero.

  • As always you can assign an instance a value on its creation and use that instead.

  • Ashley , would be nice to have a choice to either push to back or to the front of the list when creating objects. I know it may seem like a rare case that a person would want to do this, but it would make certain things easier and require less events/etc.

    As it is now, I can't accomplish what I want without having to create variables to record UIDs, and then extra events to pick them appropriately. I am forced to create more clutter due to the instance list being ordered only one way, and having to recreate that order differently through variables,events.

  • And what happens to the object it's replacing?

  • It wouldn't replace any object. I want to create an object at the front of the list, prepend it to the list.

    This is something I think would be easy to implement, Ashley?

  • Maybe you can elaborate on watcha wanna accomplish. Help can not be far away then. Anything is more easy than what you propose now. Say i want to run trough the instances ordered by X. I cant do that anymore without an IID that goes with that picklist.

    What newt says is a good solution, but in your case i suppose destroying an object makes a gap in the list that you don't like ? But UID's have gaps too.

  • Couldn't you just pretend that the object you just created is the first instance, say change the instances frame for example.

    You haven't given a reason why something like that needs to be doable.

  • I'm not sure what is so difficult to understand here. You have a list of instances. You create one, and it is added to the end of that list by default.

    Now, if I have an event to Pick Nth Instance, it picks based on the order of that list.

    For example:

    I create 5 instances, and they are ordered in succession. I can Pick Nth Instance with Instance.count-1 to choose the last one that was created. Or I could pick 0, the first instance created. I don't care when they were created, because I know which one I can pick because I know the order they are in.

    Now, these 5 instances- their order is important, but I need to destroy the first instance and create a new instance in its' place. Destroying the first instance is simple. But now, my code, which can easily just pick instance with iid=0, will pick the second instance that was originally created- not the new one I'm creating.

    So, instead of it being easy and allowing me to create the instance at the front of the list, I have to create at the end of the list and now use a second piece of data to represent its' order. Or I have to reposition the previous ones, transfer their properties to each other if they have any, etc..

    If I could just create instance and choose to create it at front of list, I can avoid all the extra stuff. It should be pretty obvious the benefits?

    So yeah, I know it can be done other ways, but the point here is to make things better/easier/quicker/etc. When you start making complicated programs, these little things can be extremely useful.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry 4 u, u did't read me. U r wrong.

    Ther is no 'list of instances', there is only a Selected Object List.

    In the rare case that you pick them all, you have something that you personal call a 'list of instances'.

    There is not such thing as 'my fish', relative to those in the sea, in that rarely case that i catch one, i can call it mine, yet there is a majority that is not.

    The IID is the index of an object in the Selected Object List. (SOL)

    https://www.scirra.com/manual/29/object-type

  • 99Instances2Go ,

    An object type has an array:

    type.instances[]

    This holds essentially a list of instances, and when you create a new instance, it gets added to the end of it.

    What I want is an option to add to the beginning of that Array.

  • Instances are identical. Unless you know something we don't.

  • Instances are identical. Unless you know something we don't.

    No they aren't, that's why there is an array of instances, to hold all the different ones. When there is no SOL, it references the type.instance[] array. Pick Nth Instance would pick based on the index of that array.

    I'm looking to see if I can create a plugin that can reorder the type.instance[] array. Not sure if it can, but even so, would be nice to have this implemented without needing a plugin.

  • So let's get this straight.

    You want to destroy the first instance, and create a new instance, and have it replace the first instance?

  • I want to be able to create an object, specifying whether to add the instance to the front of the instance array or the back.

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