How do I set data from array to global variable (type number) correctly?

0 favourites
  • 9 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hi!

    I have 2D array "2DArray" making by AJAX requesting .txt file:

    11;22;33;44;

    55;66;77;88;

    and I have global variable (type number):

    "TESTvariable"

    I need to set "22" to "TESTvariable"

    I make this:

    Set "TESTvariable" to 2DArray.At(0,1,";")

    But I've got a 0 to "TESTvariable"

    So I make this:

    int(Set TEST to 2DArray.At(0,1,";"))

    But I've got a 0 to "TESTvariable" again.

    How do I set data from array to global variable (type number) correctly?

  • If you load a text file that contains 11;22;33;44;55;66;77;88 to an array, it will be at 0,0 I presume, so you can use tokenat to find 22.

    Set Testvariable to tokenat(Array.At(0,0),1,";")

  • If you load a text file that contains 11;22;33;44;55;66;77;88 to an array, it will be at 0,0 I presume, so you can use tokenat to find 22.

    Set Testvariable to tokenat(Array.At(0,0),1,";")

    I just chek it by "tokenat".

    Now I've got "NaN" in "TESTvariable" :(

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What does your array look like ?, I presumed you loaded the text file into an array at 0,0

  • NaN means "not a number", so you may have to use int(tokenat(Array.At(0,0),1,";"))

  • Global Numbers work, this works for me.

  • What does your array look like ?, I presumed you loaded the text file into an array at 0,0

    I have Array with such ";" separator

  • ok, if you wanted to set the value 22 to a variable from your array here it would be.

    Set Testvariable to tokenat(Array.At(4,0),3,";")

  • ok, if you wanted to set the value 22 to a variable from your array here it would be.

    Set Testvariable to tokenat(Array.At(4,0),3,";")

    thank you very much! everything worked. I did a little differently and it didn't work because of double "(": tokenat(Array.At((4,0),3,";"))

    THANKS!!!!!

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