Position 21 Objects with Arrays and Loops: HOW?

  • I have 21 objects, all the same, duplicates.

    Every time I change something about these objects, and make them nicer and more functional, I have to delete 20 of them and manually make 20 duplicates, and then fight with the editor to drag and drop them where they're supposed to be in the scene.

    They always go back to the same 21 spots on the playing field.

    And there's 21 other objects that go into the middle of these objects, which I'm also constantly updating and improving, and have to do the same thing with when I'm happy with improvements.

    Is there a way to use the loops and arrays to store the 21 positions and then loop over the first 21 objects, put them into their respective places on the play area, then iterate over the other 21 objects and centre them to the each of their respective parents from the first 21 objects?

  • @Deeeds Yes there is, but I don’t think I’d be able to just simply explain it to you in text. Maybe I’ll try make an example for you, but if it were me I would just not duplicate the initial object until I’m certain the original is as good as it can get. I’m not sure how long it’ll take me.

  • @Aidan-Oxley

    Yes, I understand what you're saying about finishing something first, then distributing it. But that's not always possible because... for example, each of these 21 objects interacts with several others. Without experimentation within the full context of their relationships it's not possible to isolate one and determine the ideal. And please, given the fact I'm not a complete idiot, assume I've already done as much of that predesign as is possible without the context of others in the game world to determine the ideal interactions and player experience.

    with words:

    I'm assuming its one of the loops combined with arrays that will make this possible, as this is how it would be done in any other environment.

    The thing that I'm missing is understanding how to group objects for consideration by the conditional that's determining who to put where, that somehow individualises each instance and doesn't make the mistake of applying two different positions to one object.

    I'm assuming tags would be the way to do this differentiating, but can't see how to serialise/individualise the instances in a way the loop knows about.

    So, let's say:

    Tags are parent and child.

    The Arrays will need to be two, one for X values and one for Y values because there's no vector type and/or vector storage available (that I know of) within hyperPad.

    So we have two arrays, one is 21 X values, the other is 21 Y values.

    Each of these must be a pair, by virtue of sharing the same index in their respective arrays.

    In this way we're making an imaginary two dimensional Array [X, Y]

    We can't use a dictionary because some of the X values are the same, and some of the Y values are the same, so there's no unique key available, nor are they knowable without making another Array of those key values.

    So the loop starts by needing to know the length of one of the Arrays, probably X.

    Having found that, the loop then needs to be this length, and for each index value it needs to seek a unique object and apply the setting of X and Y values from the current index in each array to the position values of this object. Then release this object and grab the next one and the next two "pairs" of X and Y from the array.

    Having done this for the parent tag, the next loop doesn't need the arrays of positions, it can seek out positions within each of the parents and apply it to the children, making relative relationships in position during this iteration over the loop.

    This is a pretty common thing to do in all sorts of environments, but probably somewhat of a spaghetti mess in this environment.

  • @Deeeds you can use an attribute to give an object in a tag a unique ID, then use a 'for each' loop with the tag selected. It will loop through each object in the tag and pass the object down to any other behaviours using the tag under the loop. So you could get an array value based on the order they spawned in, or whatever other method they use to get an ID.

    If you want to spawn them at a specific point though, you can use the spawn on area behaviour to spawn them, and set both corners of the area to the point you want to spawn them at. You could do this from x and y arrays using a regular loop with the array length as number of loops, and get array value with the index of the loop.

    It would be nice if we could select spawned objects without loops though.

  • @Jack8680 If I'm making the objects in the Scene Editor, and they all have unique names because of this, do I need the attribute?

  • @Jack8680 And completely agree, named access to ANY and all objects would be a huge benefit. Massive. World changing.

  • @Deeeds it depends what exactly you're looking to do. If it doesn't matter which object moves to which point, you could just use the for each loop and use the index to choose a position to move them to, but if you want a specific object to move to a specific point you'd need to use an attribute.

  • @Jack8680 EDIT: Stalled browser copied in a sentence from another post: DELETED:

    So the attribute could be an integer, and 0 through to 20 (21 objects) by which to refer to them in the loop? Is this sort of sorting possible in hyperPad?

  • @Jack8680 I'm cursed by the 120 second timer before I can post follow ups.

  • @Deeeds you don't need an id to loop through the objects, the for each loop automatically loops through all objects in the tag and sends that specific object to any behaviours below that refer to that tag. For example:

    For each tagobject:
        Get ID of tagobject
        MoveX = xArray[ID]
        MoveY = yArray[ID]
        Move tagobject to (MoveX,MoveY)

  • Or instead of ID you could get rid of the get attribute and use the loop index to get the position, if it's not a specific object that needs moving.

  • @Jack8680 Sorry for these stupid questions:

    Is "Get ID" a use of Get Attribute?

    Where ID is the type of attribute and the ID's value could be string or Int?

  • @Deeeds yeah it's a get attribute. You could use strings as ID too by using a dictionary rather than an array. ID is just the attribute name.

Log in to reply