Accessing Construct Array In JavaScript - help :(

0 favourites
  • 3 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • Hey gang!

    So, I've gotten a pretty good handle on integrating simple JavaScript functions into my project. I'm now trying to use JavaScript in conjunction with an Array I have in my project...

    Here's what's going down:

    I have an array (ARR_SongRelease) that stores generated songs: X[0] = Artist Name, X[1] = Song Name, X[2] = Streams Generated For That Song. Whenever a new song is generated in the game, it adds a new entry on the Array's 'Y' access. The array is saved in local storage! This all works great :)

    However, I'm trying to display the top 15 songs (based on the Streams, or X[2] value).

    Here is what my main.js function is looking like:

    And here is what's happening in the event sheet:

    From a little bit of debugging, I've concluded that the issue has something to do with how ARR_SongRelease is being requested, because the code works perfectly fine in VS Codium using a test array. I'm wondering if I have a simple syntax issue somewhere (as I've never tried to call upon a Construct array in JS before), or if the issue is deeper, like my Local Storage, and it's trying to run this function before the data from the Array is even loaded?

    Any and all help would be greatly appreciated :)

  • When using js in construct bear in mind you have to get used to a lot more debugging.

    Probably your issue is a construct array object isn’t a js array. If you get the array instance from js these are the methods you have access to:

    construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/plugin-interfaces/array

    Basically just getters and setters.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound, got it. So it seems like I need to rework my logic a little bit. Thanks for the insight!

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