Can I use a single array for this?

0 favourites
  • 11 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hey everybody, I'm new to Construct and programming in general. I'm working on a prototype for a game where a shadow enemy follows the player's exact path. I have it working here: media.giphy.com/media/YkfNNiJS1ML5sUmz5R/source.gif

    Here's my event sheet:

    I have a couple of questions:

    1. Is it possible to do this with one array instead of two? I wasn't sure how to get the Y value for a single array.

    2. Should I be worried about performance/storage building these arrays? E.g. should I try to clear the values that have already been used?

    Thanks for your help!

    Tagged:

  • 1. You use one array with 2 different columns, such as 0,0 and 0,1 then 1,0 and 1,1 where 0 is the X co-ord and 1 is the Y co-ords, you would push back X and then Y you need to set in the same row and for this you need to know the row's X value so use the array's width to work it out maybe array.width-1,1, where the X is set at array.width-1,0 when you push it

    2. You can pop the top row of the array as you push one in

  • Thanks for the quick response, lionz! I'll try what you suggested.

  • Hey lionz I can't get this to work for the life of me. Any chance you can set up an event sheet?

    I've tried a ton of combinations of push, insert and set actions for the array but I can't seem to get the y value to go into the right place. The only way it's worked for me is by loading a premade array from the array editor. This is what I want my array to look like, where 0, n contains the x coordinates and 1, n contains the y coordinates.

  • Just jumping in between. Regarding your main question:-

    1.) I have no issues in maintaining 2 arrays. When life is easy with 2 arrays then why to go with 1 array

    2.) DEFINITELY YES. There is a limit on the length of the array. And it will surely have impact on performance.So try to make such a mechanism that useless data is also getting deleted

  • I just made an example for you. Maybe it may help

    (Remember drag the black box quite slowly)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It does not use concept of array. And in my opinion it is quite flexible to use.

  • Hey Cascade-games, thanks for chiming in! You're right that using 2 arrays was easy. I just feel like a failure for not being able to figure out how to get it to work with a single one.

    This is a super cool solution. I love how you even visualize the path the enemy is taking. I'm going to have to study your event sheet to make sure I'm following but this could be a great alternative to my approach. Thank you!

  • I will check it out but you were already there pretty much with the logic from your first screenshot it was just about tweaking a few things.

    For Player.Y it is set at array.width-1,1 after the push back player X action

    You need to ensure the array height is at least 2 or the column doesnt exist for the player Y.

    Run it in debug mode to see what is happening with the values.

    The main reason you should get used to manipulating a single array is because when it comes to importing a data file like the one you have provided it should be imported as is into one array.

  • Hey lionz,

    I got it working with a single, array!

    The one thing I haven't figured out how to do is pop the values within the same condition. When I try that, it ends up deleting the y axis. I'm still tinkering though.

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