How do I draw a leaderboard from my array?

0 favourites
  • 8 posts
From the Asset Store
You need this package if you want to program a Street Fighter or battle game.
  • Heya all.

    I'm sucking at this...and need some major help ◡̈...I'm desperate.

    I have a music career simulator game in the works. There are AI-controlled artists who'll randomly write songs. I have 2 arrays thus far for storing data: "ArrayAIStats" and "ArraySongRelease."

    "ArrayAIStats" stores and updates information as the game progresses -- information such as the artists' names, their total number of fans, etc..

    "ArraySongRelease" is choosing an AI-controlled artist at random, and based off their current number of fans, is generating a total number of plays which their new song will receive.

    It's being logged as:

    x(0) = artist name

    x(1) = song name

    x(2) = plays generated

    whenever a new song is released, the array adds a new Y entry, and repeats the process.

    ^ all of this works great.

    The issue I'm having is:

    I'm trying to create a "Top Songs" layout/event sheet where I display the songs stored in "ArraySongRelease," and sort them in ranking order based off their plays (X=2).

    I have 2 texts, and I'm trying to have Text1 show the name and song title, like:

    Array.SongRelease.at(0, cur.Y) & " - " & Array.SongRelease.at(1, cur.Y)

    and have Text2 show the total number of plays, like:

    Array.SongRelease.at(2, cur.Y)

    I can't seem to figure it out myself, and would love love love some help!!!

  • I have 2 texts, and I'm trying to have Text1 show the name and song title, like:

    Array.SongRelease.at(0, cur.Y) & " - " & Array.SongRelease.at(1, cur.Y)

    and have Text2 show the total number of plays, like:

    Array.SongRelease.at(2, cur.Y)

    I can't seem to figure it out myself, and would love love love some help!!!

    There are many questions together so let's deal with this one for now:

    I'm trying to have Text1 show the name and song title

    This sounds like it is for a single song but you are using "Cur.Y" which is used on "Array For Loop" which it will loop through all the Y.

    If you just need a single song and you know on which Y is located then you should use the Index number directly.

    Example:

    If it was on (Y = 1)

    Array.SongRelease.at(2, 1)

    Unless you are printing all the songs using "For Each Y" in that case you will use "Cur.Y" as you do now.

  • Thanks tarek2 for the reply!

    This sounds like it is for a single song but you are using "Cur.Y" which is used on "Array For Loop" which it will loop through all the Y

    Sorry, I'll condense what I'm looking for. There can be, in theory, hundreds of songs generated in "ArraySongRelease."

    I want to show the top 10 on my layout, based off the value stored on X(2).

    How can I go about doing this? "Array For Loop?" Is there a manual/guide somewhere where I can learn more about "Array For Loop"? ◡̈

  • Here's a diagram to better visualize what I'm trying to get across.

    So, the upper half of the image is a visual representation of what my Array is doing. Every time a new song is generated, the array adds a new Y column, and logs the artist(X=0), song title(X=1), and plays(X=2).

    The lower half of the image is what I'm trying to achieve in my layout. My diagram example stops at 4, but I want to showcase the top 10 songs based off their plays.

    I wish to know how to cycle through the array, and show via text the most-played songs that have come out.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I see,

    In that case, if you want to maintain the same structure without making any changes then you can use a second Array to do the sorting.

    On your Picture you store the first Artist on (Y = 1) instead of (Y =0) so according to that:

    Here is an example:

    https://www.dropbox.com/s/c6vmd3x43o0sq2p/Array%20Sort%20Songs.c3p?dl=0

  • tarek2 you're flippin awesome. I copied whatcha did, threw it in my game, and the sorting works!! I'm fumbling on the text part though. I had to adjust the "create object" parameters of the the Table Grid to fit the viewport of the game. Perhaps I'm losing it, 'cause in your demo it works, but I don't see where/how the text is being binded to the table grid??

  • Np Glad was helpful

    I'm fumbling on the text part though. I had to adjust the "create object" parameters of the the Table Grid to fit the viewport of the game. Perhaps I'm losing it, 'cause in your demo it works, but I don't see where/how the text is being binded to the table grid??

    I think the issue you have could be that you didn't create the container between the two objects (Text & Table_Grid).

    If you click on any of the two objects and look at the Left side editor panel, on the "Container" section you will see I link them together.

    This what it does is if you:

    -Create one object from the container the other objects inside the container creates automatically with it.

    -Destroy one object from the container the other objects inside the container get destroyed automatically with it.

    -Pick one object from the container the other objects inside the container get Picked automatically with it.

    You can read more about containers here:

    https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/objects/containers

    The Grid was just for quick testing, didn't know you want to create the grid dynamically swell, here is how I will create the Grid dynamically.

    You can keep the old one though if you like it more, there is nothing wrong with it. Here I just added some extra Variables to adjust the grid easily and cut down the Actions.

    New Example:

    https://www.dropbox.com/s/cedpv6dl1wnz1pc/Array%20Sort%20Songs2.c3p?dl=0

  • tarek2 wow, after years of Construct...I had absolutely no idea you could do that. What a brain bender...

    Thanks for all your help; you saved the day! Arrays are kind of an intense animal for me, I was struggling with this for days. I totally appreciate the examples and help you gave!!!

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