How do I add an instance with iid=0?

Get help using Construct 2

Post » Thu Jun 23, 2016 8:40 pm

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!?
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Thu Jun 23, 2016 8:53 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jun 23, 2016 8:53 pm

As always you can assign an instance a value on its creation and use that instead.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Jun 23, 2016 9:02 pm

@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.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Thu Jun 23, 2016 9:04 pm

And what happens to the object it's replacing?
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Jun 23, 2016 9:07 pm

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?
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Thu Jun 23, 2016 9:14 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jun 23, 2016 9:24 pm

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.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Jun 23, 2016 9:46 pm

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.
B
48
S
23
G
66
Posts: 1,144
Reputation: 39,059

Post » Thu Jun 23, 2016 10:11 pm

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
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 29 guests