Preloaded arrays

  • 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?

  • Shameless bump...

  • 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?

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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

  • 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".

    > 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.

  • 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.

  • 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.

  • > 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.

    Yup! Just saying that being able to load only one file at a time is quite a bummer

  • The idea is to make editing the data file easier since xml and json are tedious.

    Easier to have your own format/parser?

    XML tedious?

    Disagree.

    One example of a xml dictionary that I'm using right now:

    <?xml version='1.0' encoding='utf-8'?>

    <dictionary version='1.0' selected_language='eng'>

    <word key='hi'>

    <translation language='spa'>Hola</translation>

    <translation language='eng'>Hello</translation>

    </word>

    <word key='bye'>

    <translation language='spa'>Adios</translation>

    <translation language='eng'>Good bye</translation>

    </word>

    </dictionary>

    What kind of file would be clearer than that?

    The XML parser in C2 is about 10 lines.

  • Yup! Just saying that being able to load only one file at a time is quite a bummer

    Mmm... that is not 100% correct.

    You can REQUEST multiple files and inside "On complete" AJAX.LastData refers only to the data loaded in the tag defined at your "On complete" event.

  • > Yup! Just saying that being able to load only one file at a time is quite a bummer

    >

    Mmm... that is not 100% correct.

    You can REQUEST multiple files and inside "On complete" AJAX.LastData refers only to the data loaded in the tag defined at your "On complete" event.

    Yeah, that's what I meant, only one files' lastdata at a time.

  • Yeah, that's what I meant, only one lastdata at a time.

    Don't understand your problem.

    You can have:

    • 10 different file requests.
    • 10 different "AJAX on complete" with AJAX.lastdata inside.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)