Numbers from CSV to Array

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • I'm making a game using decks of cards, and trying to figure out the most effective way to handle the cards for each "deck". I'm still learning as I go. So, short story long, to explain why I'd need this in the first place (and in case the whole thing is bonkers to start with,a nd you have a much simpler way to do it all):

    I've been using the general idea of this video for making and shuffling a deck using arrays and animation frames, which works great: youtu.be/vmkwx70_5a8

    In this game though, the deck of cards that the player plays against has different cards in it for each level. I've tried to think of a few ways on how to manage this and how to tell the game which cards to use and shuffle, but as mentioned I'm unsure if I'm doing it effectively, and would love your thoughts on it - maybe I'm making it a lot worse than it could be.

    So far I've made a CSV file using Rex's CSV plugin that holds each card and the info for it (a name and a number stat for instance, to keep it simple.)

    I've then made a sprite on the game screen, with an animation frame for every single card in the game. The shuffled array from the video above will then tell the sprite which card to show. Works like a charm so far, with the one simple stack of cards I've made for testing. But eventually I'll need it to be able to use more than one deck of cards.

    TL;DR:

    For this, I hope to use the CSV to tell the deck Array which frame numbers to include before shuffling. ( fx. 1, 1, 3, 5, 5, 6, 6, 6, 6 instead of just 1-6).

    For instance: In deck1, there should be two 5s added to the array. I'm just still stumped on how this would work in code, though, if it's possible to do it this way.

    So here is the question, finally: How would I best tell the array to add the designated amount of numbers from the CSV above? (Add number in "5" x the number in "5","deck1" somehow?)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If your question is about reading/parsing of the CSV file, Rex has several plugins for that:

    construct.net/forum/extending-construct-2/addons-29/plugin-csv-csv2array-csv2dicti-41868

    You can load CVS into an array, or you can use CSV plugin expressions, for example CSV.At("Card 5","Stat")

    .

    By the way, I think the structure of your CSV is wrong. If "Card 1", "Card 2"... are column names, then they should be in the first row, not in the second.

  • I am already using his plugins, and I've been able to fetch data nicely from them so far. Maybe I just made my example look wrong.

    My problem is that rather than enter "5" from that cell into the array (I can do taht with what you wrote) I want to enter "5" the number of times the designated cell tells it to. In this case, I want 2 "5"s in the array, and 4 "6"s for instance.

    I'm not sure how to tell it to do that.

  • Then I think you need to fill this array "manually" (not using the CSV2Array plugin).

    Set numberOfCards to CSV.At("6", "Deck1")
    Repeat numberOfCards times -> CardArray push "6"
    

    this will add 4 copies of card "6" into the array

  • Thanks a lot! After messing about with some other minor stuff that got in my way, I tried doing that, and it works just as I wanted it to :) That helped a lot.

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