Why are Array's backwards in Construct???

0 favourites
  • 9 posts
From the Asset Store
Casino? money? who knows? but the target is the same!
  • I've been programming since 1995 and we load arrays like this:

    const int NAME=0, GAMES_PLAYED=1,UNLOCKED_BOSS=2;

    Array[0][NAME] = "Andrew";

    Array[0][GAMES_PLAYED] = 42;

    Array[0][UNLOCKED_BOSS] = "yes";

    Array[1][NAME] = "John";

    Array[1][GAMES_PLAYED] = 11;

    Array[1][UNLOCKED_BOSS] = "no";

    Array[2][NAME] = "Fred";

    Array[2][GAMES_PLAYED] = 2;

    Array[2][UNLOCKED_BOSS] = "no";

    The excel spreadsheet would look like this:

    ID NAME GP UNLOCK

    ------------------------------

    0 Andrew 42 yes

    1 John 11 no

    2 Fred 2 no

    If you know anything about arrays in construct it swaps rows with columns. WHY??? It's incredibly confusing!

  • can't figure out how to format the text!! why is this forum's features SO BAD!!??

  • X usually comes before y which comes before z. x is horizontal and y is vertical. Easier to visualize based on a coordinate system maybe? Also consistent with the other ways xyz is handled in construct. Perhaps it makes more sense to someone who has not had programming experience before.

  • Try Construct 3

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

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

    I have programmed for decades too, and use arrays in Construct all the time. I guess I have trained myself to not look at the X and Y labels, and just think Row and Column. When I make loops to go through an array I use tags of "Row" and "Column" so I see:

    Array - set value at (loopindex("Row"), loopindex("Column")) = value

    and to get the number of rows, it is array.width

    we don't get constants, but I do sometimes make variables for field name like in your example to make code easier to read when I come back to it. then code looks like:

    Array - set value at (loopindex("Row"), Player_Name) = value

    Array - set value at (loopindex("Row"), Games_Played) = value

    so, just because it says "Set at XY" doesn't mean you have to switch the rows and columns around.

  • AllanR yes there are constants in C3 and C2.. I use them all the time! It's a checkbox when you create the global.

    when I make tables in excel/google sheets I've always have my entire "record" on 1 row, each field is a column.

    so when I do - For Each X (in the array) it is looping through columns, not rows!

    it's just completely upside down to me! Maybe it's cultural?? I used to be a database guy back in the day, so maybe I'm just bias... I use LOTS of tables in my games.

  • I completely forgot about that check box - and I have used it to...

    I am also a database guy. I haven't used the C3 array editor, so I don't know how that works. I use PHP/MySQL and AJAX to load data from a database, and put the rows in X, and fields in Y, so a For Each X gives me rows.

    if the only option is to load in backwards in C3, you could transpose the data in Excel just before you load it, then it should look right...

  • transpose them and just have ugly tables :(

  • well, just transpose as an intermediate step in the import process, so it ends up the right way in Construct.

    I wouldn't want to keep the data that way either!

    yeah, it is an extra step, but it would make life easier in C3.

  • but also you can't resort your columns without having to change all your constant variables.

    I would like it to be how Dictionaries are.. except Dictionaries can only store 1 field for some reason...

    but notice how Dictionaries store their info... up and down! not left to right...

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