Input/Output text using Arrays

0 favourites
  • 8 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hello,

    So I previously posted when I had just started working with construct but now that I have a firmer grasp on both what my concept is and how I want it to function, I turn to you, constructers, for help.

    I am working on a neuroscience project regarding decision making in a respectable institution in Europe. I am a psychologist and just dabbling into programming out of necessity, so I apologise if any of what I ask is redundant/easy and I just can't see it.

    My game (visually only, please disregard the code as the one in this is old and deprecated) will be as follows: scirra.com/arcade/puzzle-games/beta-spinner-493

    So my objective is to collect data from the player's input -key presses or screen touch, on mobile. To do so I need to output said inputs into local storage along with a timestamp, locally save all this data on a .json or whatever file and then send it somehow to my servers. Someone suggested I used this (scirra.com/forum/plugin-send-a-mail-using-mandrill-update_t109399?&hilit=plugin+social+mail) as a way to send the information to an email server.

    However this isn't my biggest issue at the moment. I'm trying to input the coordinates for the balls that grow and which wave we currently are in- say an input matrix that looks like "TimeToActivateSprite(in ms), InstanceOfTheSpriteToActivate; WaveNumber" (or "1.039, 3; 3").

    This would mean that the instance 3 of spriteX would spawn at 1.039ms, and the game would know we are currently in wave 3 (and consequently should act according to that).

    Now, I can easily input my data from a text file into an Array by using some expression like "set array at X to tokenat(x)" (where I am aware I can define my separators to ,;| or whatever to define rows and collumns) or "set array at X to Ajax.LastData". The issue arrises when I can't for my life fill the whole array at once using my text input. I mean, I have over 1000 data rows of input generated on matlab and I don't want to manually input them 1000 times or even use different input files for each column because I will eventually need to change one of the coordinates and this would be a huge pain (especially when updating the game after it's launched).

    I'm aware this is a fairly complex issue as I've seen several topics of people struggling with this and none resolved. Any input would be valuable. I may (almost certainly) be overcomplicating this so please be harsh and give me your best shot.

    Also, if you would be interested in helping further on this project please email me at and I'd be happy to give more info on what the scientific part of this study is and credit you on the game credits along with myself (and even other ways of repaying for the help according to your contribution)

    Thanks!

    tl;dr: 1.How do I input data to my game via a matrix like txt file.

    2.How do I output key presses onto a text file and send it to my server.

    3. FOR SCIENCE!

  • I've used the CSV to Array plugin for inputting large amount of data, could this work for you?

  • Hello,

    I've read extensively on this plugin and I can't understand how it works. Am I supposed to use Ajax to call my imported .csv or not?

    And how do I import the whole file into an Array?

    Thank you for the help, I'm feeling really lost even after reading dozens of topics on this.

  • Currently I'm using a c2array structure in a txt file.

    {"c2array":true,"firstRowIsColumnNames":true,"size":[4,3,1],"data":[[["Id"],["Name"],["Status"]],[[999],["Spain"],["Peace"]],[[998],["France"],["Peace"]],[[997],["Portugal"],["Peace"]]]}[/code:2g8po9ht]
    Next step, should be easy,
    
    [img="http://s3.postimg.org/tbxfxuopf/next.jpg"]
  • Hey man,

    Your response is pretty usefull, but I would much prefer LittleStain 's method as CSV is a much more simple file. Anyway, if you could send me a capx that would be marvelous.

    Thanks a ton!

  • First using Ajax I request the *.csv file (which I put in my project files)

    Then I call the csvtoArray to put the data into an array

  • Use ajax to read a project file (or file selected with the file chooser) into a variable.

    Let's say you have a simple csv:

    1;2.1;3;4
    1.1;2;5;8
    3;1;-1;6[/code:34zgy6k5]
    
    each line is a row obviously and colums are separated by ;. This is pretty standard a pretty standard .csv format.
    If you read the file with ajax you then can parse it into an array with a simple nested for loop.
    
    Example code:
    [img="http://666kb.com/i/d06a0iuzer52d2ae4.png"]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks a lot people!

    I have a follow up question then. Once I have all my data on my array, I want to constantly compare my "Timer" variable with the next value in one of the columns in my array and spawn an instance of an object (identified in the second column) when the "Timer" var matches a value on my column (values are ordered so It'd be preferable if somehow it could read one only after successfully matching the previous.

    I'm lost as in how to make C2 check one specific value on the array without having to manually specify it.

    Something like: whenever timer matches, give me Array.Indexof("var") and then proceed to give me the value in the same index, in a different column... I have no idea how to achieve this.

    I'll upload a screenshot of where I'm at in a few minutes.

    Thanks a lot!

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