Input/Output text using Arrays

Get help using Construct 2

Post » Wed Jul 08, 2015 12:17 pm

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 [email protected] 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!
B
10
S
2
Posts: 27
Reputation: 617

Post » Wed Jul 08, 2015 12:35 pm

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

plugin-csv-csv2array-csv2dictionary_t64326
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jul 08, 2015 1:31 pm

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.
B
10
S
2
Posts: 27
Reputation: 617

Post » Wed Jul 08, 2015 1:57 pm

Currently I'm using a c2array structure in a txt file.
Code: Select all
{"c2array":true,"firstRowIsColumnNames":true,"size":[4,3,1],"data":[[["Id"],["Name"],["Status"]],[[999],["Spain"],["Peace"]],[[998],["France"],["Peace"]],[[997],["Portugal"],["Peace"]]]}

Next step, should be easy,

Image
B
15
S
5
Posts: 40
Reputation: 1,221

Post » Wed Jul 08, 2015 2:10 pm

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!
B
10
S
2
Posts: 27
Reputation: 617

Post » Wed Jul 08, 2015 2:36 pm

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

Image
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jul 08, 2015 2:50 pm

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:

Code: Select all
1;2.1;3;4
1.1;2;5;8
3;1;-1;6


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:
Image
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Wed Jul 08, 2015 3:17 pm

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!
B
10
S
2
Posts: 27
Reputation: 617


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 26 guests