How do I get X,Y Values of Array to Edit Z during Gameplay?

0 favourites
  • 6 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I am not talking about the examples I've seen where player inputs text and then the text changes a value. On those the values are always known. I am talking about the ability to auto select ArrayX and ArrayY values based off of in-game actions. Like a player placing a building on random objects(tiles) that are already mapped to an array.

    I am aware I will have to implement a 3d Array. I am not 100% sure how that works. From my understanding (X0,Y0,Z0) has one value and then (X0,Y0,Z1) would just be second piece of information for (X0,Y0)? Do new Z layers "stack" above or below the current existing layers? When using a 3d Array can I add a new Z layer on an existing Array without effecting it's existing values and more important messing up code? I am thinking I can but want to be sure before I end up messing something up and not realizing until it is to late.

    I currently have a single layer array that remembers the objects on a layer(Similar to Tiles). If a newly placed Building is covering 4 objects(Tiles) how do I collect the corresponding ArrayX, ArrayY coordinates so I can change the correct ArrayZ value? I want it so the Map loads the same way if the game is saved and reloaded.

    I know I may have to have a building only take up one Tile upon placement and then mathematically change the other effected ArrayX, ArrayY and ArrayZ values with an event. There is also a chance I may be able to implement an overlapping event. The only issue is not knowing how to get effected ArrayX and ArrayY values.

    A few more question. Is it possible to only use one Array for every level/map? Just on start of layer have it load the corresponding JSON file and auto adjust accordingly? From my understandings a JSON file is a readable string of text that Arrays can read and translate.... [X0,Y0,Z0][X0,Y1,Z0][X0,Y2,Z0].. etc. I assume all I would need is a Global Variable that changes on startup and to adjust it's size as well. Correct? Do JSON files work on all devices, P.C., mobile devices, consoles etc? The game generates a file and then the device handles it? If a device is not supported what happens?

    Capx for this project is nearly empty and can be redone easily. I don't mind if the set-up for this is a small bit tedious. I am more about performance and ease of workflow after it is set-up. Plus once it is set up the chances are small that it will have to set it up again, possibly just a number change here and there.

    I have read a lot already, these are just questions I haven't caught the answers to. I know this is a lot for one post and it may be all over the place. Sorry about the length of the post, the width is average.

    I will be away for a while.

    Thanks in advance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Think of a 3D array as a Rubik's cube. If you look at it straight on, you have three columns and three rows, that's X & Y. Now move your head a little and you see there are more elements behind that front face, that is Z. So 0,0,0 is that first cube at the top left. 0,0,1 is the cube behind that first one. 0,0,2 is the last one, in Z, for that top left position.

    Your tilemap addresses the same as the array in X&Y. Z let's you store as many different data items as needed in that stack behind that front face.

    There are expressions on the tile map to convert from a screen coordinate to a tile grid position, so you can translate any position to a tile, and any tile to a position.

  • Adding to previous info.

    Say you set the names of a footbal team on the X-axis. And now you want to also keep there weight and there lenght.

    This will be a 2D array. And the adresses in the Array are like this:

    player 0 name on array(0,0)

    player 0 weight on array(0,1)

    player 0 lenght on array (0,2)

    player 1 name on array(1,0)

    player 1 weight on array(1,1)

    player 1 lenght on array (1,2)

    Reading you question, you think that you need to do this in a 3D array. Naw, not need.

    Okay, so you know the weight and you know the lenght. How do you trace back to the X ?

    Got to run trough the array with 'for each element' ..

    Use 'Compare at CurX,1' = weight

    and 'Compare at CurX,2' = lenght

    If true, CurX will be what you seek.

  • Each Tile needs more than 1 piece of info inputted into it. Each ArrayX, ArrayY coordinate can only hold one piece of info in the ArrayZ.

    What 99Instances2Go is suggesting sounds like giving every tile an X value and than using the ArrayY values for info. That sounds like it will work and actually be less complicated and smaller in size. I was asking how to get ArrayX and ArrayY on mouse click not how to compare to existing or change an existing Array Value, I know how to change/compare value. I was asking if there was a function or an easier way to go about getting ArrayX and AraryY on touch/click. I probably have asked wrong or implied something I didn't mean to, I have a habit of that... I suppose I could make an instance variable on each tile and get the ArrayX based off of the Instance Variable and then change the ArrayY needed on touch/mouse/event. I know about how a 3dArray is structured, I was asking if the ArrayZ stacked on top of another ArrayZ was automatically associated with the one below it, or if it is free to be modified. I believe I now know it is just a separate piece of info and only the location is different, it can be used in anyway one thinks of.

    Thank you both.

  • I made an example here.

    You want to go for a 3D array ? Just because. Up to you.

  • 99Instances2Go Thanks. I looked at it. It will be useful.

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