How do I add an instance with iid=0?

Get help using Construct 2

Post » Fri Jun 24, 2016 2:01 am

Ok show and tell.

Edit:
Link deleted
Last edited by newt on Fri Jun 24, 2016 4:49 pm, edited 1 time in total.
Image ImageImage
B
169
S
50
G
169
Posts: 8,285
Reputation: 108,214

Post » Fri Jun 24, 2016 2:21 am

@newt , in your capx you aren't even trying to do what I need to do- you're doing something way simpler than what I need to do.
Also, the point isn't to prove you can do what I want to do in some other way- the point here is that I need a way that solves my problems. The current ways available produce issues, whereas the features I describe would solve them. You don't seem to have my problems because you aren't trying to do the things I'm doing, so I'm not sure you'd understand why I need them.
B
43
S
19
G
65
Posts: 1,101
Reputation: 37,939

Post » Fri Jun 24, 2016 2:34 am

My point is I don't know why you need it to work that way when it already is that way, it's just not how you see it.
You have to come up with some way to show what you want to happen, and why it needs to be done.

Good luck.
Image ImageImage
B
169
S
50
G
169
Posts: 8,285
Reputation: 108,214

Post » Fri Jun 24, 2016 2:53 am

I've explained it pretty clearly already.
When you create an object, that object can be picked by picking the object.count-1.
So if I have events that rely on index 0, and I need to create an object with that index, I can't without having to add other things- whether it is events/variables. These extra things add complexity to an already complex procedure. I want to minimize that so that my events are clearer/minimal- allowing less opportunity for errors and improve my ability to create more events that do what I need without trying to jump through hoops, juggle variables, etc.
It's great that you haven't run into my problems, or don't find certain things overly complicated than they need to be, but for me there are issues I see that could be solved if I have these features.
B
43
S
19
G
65
Posts: 1,101
Reputation: 37,939

Post » Fri Jun 24, 2016 5:09 am

You probably could do it with a plugin to manipulate the instance list. In the edittime.js make an action that takes an object type as a parameter. Next in runtime.js you can get the instance list and manipulate that. Here's a reference of what you can do with arrays in javascript:
http://www.tutorialspoint.com/javascrip ... object.htm

Actually after writing that out I realized it's more complex than that since new objects aren't added to that list till a toplevel event. So the action wouldn't work on newly created objects. It's probably a non-trivial change in c2's engine as well because of that, or even because of other deep engine reasons. Not to mention it's a unique requirement so it may not be readily added.

Anyways, in cases like this I like to use an array that I store uids into as I create the objects, that way I have full control of their order. Maybe also using a function and a variable to make the expressions look less busy.

As to the op you can change the iids of an objects by destroying them and recreating them in the order you want, at the expense of losing their uids.

Maybe a more nifty feature request would be to use -1 instead of object.count-1 to pick the last instance. It currently doesn't work with the "pick nth instance" condition. It does work in expressions though: Sprite(-1).width
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Fri Jun 24, 2016 5:23 am

Yeah, an array has that functionality built in, pop front, push back, etc.
On object creation, set object.value to object.count-1, array push back value object.count-1
Then you can do your picking... object variable =arrayat(0), do foo.
Image ImageImage
B
169
S
50
G
169
Posts: 8,285
Reputation: 108,214

Post » Fri Jun 24, 2016 7:27 am

There are no benefits. Other then that there will be no need 4 you 2 read the manual.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jun 24, 2016 4:43 pm

There are no benefits

There are pros and cons to any change, so I disagree about there being no benefits. Long time users in my opinion have the privelege of requesting such advanced things because they already use the existing way to do it and see things to improve. Newer users are often directed to the manual or tutorials instead to get them aware of the common way to do things.

@Prominent
You can test your idea by finding the "ClearDeathRow" function in preview.js and replace the two places "push" is used with "unshift". It will break the logic of any other capx that relies on the normal order of iids though.

...but why stop there, we can hack a toggle using a global javascript variable.

change the line "type.instances.push(inst);" to
Code: Select all
if( window["createAtFront"])
   type.instances.unshift(inst);
else
   type.instances.push(inst);

and do the same for the other push in that function.

So by default new instances will be created at the end, but if you use the execute javascript action of the browser object with "window.createAtFront=true;" then that sets it to create from the front. It should work even when minifying.

You'll have to add the change every time you update c2, and you'll probably need to use an unmodified install whenever you encounter bugs in C2 because unofficial changes can't be supported by scirra.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Fri Jun 24, 2016 5:54 pm

Thanks @R0J0hound ,
I tried testing that. Seems like it works partly. I also changed it a little to be:
Code: Select all
         if( window["createAtFront"]){
            type.instances.unshift(inst);
            var i2, len2;
            for (i2 = 0, len2 = type.instances.length; i2 < len2; i2++)
               type.instances[i2].iid = i2;
         }else{
            type.instances.push(inst);
         }

So that the IID numbers can be referenced correctly.
The problem though is that I can't set the window.createAtFront multiple times in one event- It waits until the end of the event cycle to run ClearDeathRow I think, so whatever the createAtFront is set to last will be what it uses. And thus I can't reference the IID for the same reason until next event cycle. I end up having to use Wait 0 seconds, but I want to avoid using Wait.
So, it seems a bit messed up, as far as how it affects other picking in the same events/sub-events, since things don't get updated instantly.
B
43
S
19
G
65
Posts: 1,101
Reputation: 37,939

Post » Fri Jun 24, 2016 6:43 pm

That function is run when a top level event is reached, so the objects get destroyed and new objects added to the instance lists then. Without the hack can you access new objects by iid immediately after? If that works then something else is done behind the scenes to make that possible. Maybe instead of that second loop use "type.stale_iids = true;", so new iids are generated by the runtime instead. Untested but it seems to do that with families.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 8 guests