How do I add an instance with iid=0?

0 favourites
From the Asset Store
Add SubRip (SRT) subtitles to your videos in Construct 3
  • Ok, now tell use what is different between the one you are creating, and the one at the front, other than iid, size, angle, opacity, or position.

  • The difference is that if I can create an object at front so that it has index 0, I can design events more cleanly. There is less room for error, less potential for wrong instances to be picked, less overhead managing variables, easier to change/modify existing objects, etc.

    Ideally, I'd want to be able to create an object and specify which iid it will have, essentially inserting it anywhere in the array (not overwriting anything). Specifying front or back was just my easier suggestion.

    Seriously- this would be really useful. Maybe it's not clear to you, but I've been doing things the ways you've suggested countless times in the past, and I come to realize this sort of feature would help me a lot.

    I've been looking at plugin stuff, and I don't think it's possible to do it with a plugin, but maybe someone who knows more about creating a plugin would know whether it is possible. Hopefully Ashley will consider this feature.

  • You can push the UID of each object as it is created to the back (or front) of an array, and manipulate that array as you see fit. The array object will give you all the granular control you want. Sounds like you probably already knew that though.

    I got the impression that the developers specifically discourage using IIDs at all, which is why there are very limited expressions to utilize them.

  • The difference is that if I can create an object at front so that it has index 0, I can design events more cleanly. There is less room for error, less potential for wrong instances to be picked, less overhead managing variables, easier to change/modify existing objects, etc.

    Ideally, I'd want to be able to create an object and specify which iid it will have, essentially inserting it anywhere in the array (not overwriting anything). Specifying front or back was just my easier suggestion.

    Seriously- this would be really useful. Maybe it's not clear to you, but I've been doing things the ways you've suggested countless times in the past, and I come to realize this sort of feature would help me a lot.

    I've been looking at plugin stuff, and I don't think it's possible to do it with a plugin, but maybe someone who knows more about creating a plugin would know whether it is possible. Hopefully Ashley will consider this feature.

    I completely disagree. Moving iids around would more likely cause confusion as you are taking something and replacing it with something that is identical.

    All you are really doing is changing how it looks in your head.

    It's almost like taking the joker card, and replacing the ace, but it's worse, you're taking an ace, and replacing an ace.

    Let me make a suggestion since you are having trouble organising it.

    Why don't you start from the end of the index rather than the beginning?

    Sprite(sprite.count) gives you the last index, so every time you create something it will effectively be at your start position.

  • I can't do that because I am using both ends. I need to be able to add to either end.

    And this wouldn't move IIDs around that much- only when object is created.

    The benefits are greater than you realize.

  • Ok show and tell.

    Edit:

    Link deleted

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

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

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

  • 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

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

  • There are no benefits. Other then that there will be no need 4 you 2 read the manual.

  • [quote:3ib8m7r5]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

    if( window["createAtFront"])
       type.instances.unshift(inst);
    else
       type.instances.push(inst);[/code:3ib8m7r5]
    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.
  • Thanks R0J0hound ,

    I tried testing that. Seems like it works partly. I also changed it a little to be:

    			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);
    			}[/code:33da51nx]
    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.
  • Try Construct 3

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

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

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