Preloaded arrays

Get help using Construct 2

Post » Sun Feb 12, 2017 4:42 pm

Objective: (on start, happens once) fill arrays with predetermined data (names, parameters...) before the game starts. I want to be able to easily modify it.

What I'm doing right now:
I read each .txt (which is basically a construct array in .json) with AJAX, then copy all data with for loops into each array, so I can then do things like generating a name choosing randomly from the array. I can have each .txt in a text editor open, edit a value then save it and preview.

I know there is a JSON/XML plugin and I've seen others do things like pasting array .json code directly into an action to load an array (which is said to be dangerous for framerate) or set each cell manually with actions in the event sheet.

Is there a better/simpler solution?
B
9
S
3
Posts: 152
Reputation: 1,270

Post » Mon Feb 13, 2017 6:08 pm

Shameless bump...
B
9
S
3
Posts: 152
Reputation: 1,270

Post » Mon Feb 13, 2017 6:50 pm

1. You don't need to copy the data to an array because "Array" has the action "Load from" and it does directly from a json (as text). So you can have a json requested with AJAX and load it directly to an C2 array.
2. I don't understand your problem. Better solution for what?
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Post » Mon Feb 13, 2017 7:07 pm

Wouldn't it lag? I've heard that loading big strings using that action causes freezing
B
9
S
3
Posts: 152
Reputation: 1,270

Post » Mon Feb 13, 2017 7:10 pm

GamerGon wrote:2. I don't understand your problem. Better solution for what?


I have to use AJAX plus external files just to have arrays loaded with parameters, as reading directly from AJAX.lastdata would mean loading a file each time (not instant). A better way of handling this, is what I meant.
B
9
S
3
Posts: 152
Reputation: 1,270

Post » Mon Feb 13, 2017 7:39 pm

To me simpler would be one file to load a text from ajax. The file wouldn't be json or xml or anything complicated like that. You can come up with your own file format that you can parse pretty easy with tokencount() and tokenat() with a few events. Maybe 20 or so? The idea is to make editing the data file easier since xml and json are tedious.

Give me a more complete idea of the data in your files and I can give a more refined answer.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Mon Feb 13, 2017 7:52 pm

Three types:
-Lists (names, dialog...). Used to pick a random index
-Weapon parameters (10+ per weapon, lots of weapons). Used to pick current weapon parameters
-Font kerning values

All of these are in separate .txt's

I need all of this data to be accesible without loading and unloading files with AJAX (not instant, sadly), that's why I copy them into arrays
B
9
S
3
Posts: 152
Reputation: 1,270

Post » Mon Feb 13, 2017 7:59 pm

CloveltOc wrote:Wouldn't it lag? I've heard that loading big strings using that action causes freezing


What is "big" for you? because, 100 lines of plain text is nothing.
Lag comes into play when the file is too heavy (let's say bigger than 1mb. I've just created a file with 10.000 characters and it sized 11 kb) but you can always have a loading bar :)

There is no problem doing that, don't worry. Is the way to go. It is common to have one or more json for configuration and one xml for text (for localization purposes).

In any case, always have a plan b inside C2 "code" for any problem loading your files, using "AJAX - On error". I call that "default values".

CloveltOc wrote:
GamerGon wrote:2. I don't understand your problem. Better solution for what?


I have to use AJAX plus external files just to have arrays loaded with parameters, as reading directly from AJAX.lastdata would mean loading a file each time (not instant). A better way of handling this, is what I meant.


A "better way" is not to load those values from external files, but internal vars/arrays/dictionaries. You can have a configuration event sheet where you'll edit your values directly in C2. This way you will not need json, xml, or any other format but C2 conditions or actions.
The answer you are looking for is: "it is internal or external", there is no other way.
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Post » Mon Feb 13, 2017 8:02 pm

CloveltOc wrote:Three types:
I need all of this data to be accesible without loading and unloading files with AJAX (not instant, sadly), that's why I copy them into arrays


It's not a "game" or "Construct" thing, It's web technology. AJAX is the way to access external files.
Lead developer at Octeto Studios
Visit our portfolio at: http://www.octetostudios.com/ :)
Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Post » Mon Feb 13, 2017 8:04 pm

GamerGon wrote: A "better way" is not to load those values from external files, but internal vars/arrays/dictionaries. You can have a configuration event sheet where you'll edit your values directly in C2. This way you will not need json, xml, or any other format but C2 conditions or actions.
The answer you are looking for is: "it is internal or external", there is no other way.


Hmmm, had not considered setting values manually onto array objects on a separate event sheet... Tedious, but clean and maybe not to annoying to edit? Still, editing from a text editor is more convinient for lots of values

Would still like to know R0J0hound's opinion on this, though.
B
9
S
3
Posts: 152
Reputation: 1,270

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests