0 Favourites

How do I Store Object Positions in Arrays

  • Good evening! I'm trying to store the positions of instances of a single object sequentially in an array's index values. Here is the desired effect that I want to be applied to the array.

    As you can see, each value of the array from start to finish follows in a logical order. I want to be able to call on those values through something like an expression later on, to the effect of something like "Set position of (x) object at (Array.Width-5)"

  • Well, there's three ways you can do this (at least).

    Firstly, create them programmatically, rather than placing them on the layout with drag and drop from the C2 editor, call System.CreateObject in a for loop, then you can use loopIndex to store them in a 2D array.

    Secondly, you could give each an instance variable which is their index in the array (you could use the numbers in the text if these are containers with a sprite and text object in them) and use foreach to copy those values to an array

    Thirdly, if you know they are going to be top left to bottom right ordered, you can use for each (ordered) with an expression something like button.X + button.Y * 10000 which will order them for you in that order, as long as your layout is less than 10000 high

  • With what I have set up the first option isn't viable. Not only that, but the first option would have me call in objects at specific locations, correct? I don't want objects to be spawned at specific pixels in the layout that are solely relative to the layout. I have objects spawning relative to other objects however, which works perfectly for what I want.

    I don't think the second option or third are very viable either. Again, I'm trying to store the locations of instances of objects that are already in the layout as the array's index values.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Bump. Still working on a solution for this.

  • From the looks of this it appears that the actual index values in the array are being changed to the X and Y values of the desired objects to be stored. Is that the case or am I looking at this wrong?

    What I want is for the normal index values in the array (0 to Array.Width-1) to be kept so that I can call on them later, but I want their values to contain the positions of the objects.

    For example, let's say I have an object at (400, 500) in the layout. I store this object's position in an index of my array. So now if I said "Set position of (X) object" to Array.Width-3 (Let's say that index in the array contains the (400,500) location), X object would go to (400,500) instead of me directly telling X object to go to (400, 500)

    The idea is that no concrete position is being stored in the array because that position will change based on where the object is moved.

  • now you have something like this:

    object X set position to X= Array.Width-3,0

    ........................................ Y=Array.Width-3,1

    capx> http://s000.tinyupload.com/index.php?fi ... 8336073068

  • You sir, need to understand how amazing and helpful you are. Thanks again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
223 15,823
Tom's avatar
Tom Construct Team Founder
Unread hot topic
99 10,130
karshinkoff's avatar
karshinkoff
Unread hot topic
167 14,485
DMT2005's avatar
DMT2005