Read Settings from File

0 favourites
  • 8 posts
From the Asset Store
Creepy Sprite Font suitable font for your Dark/Horror/Halloween games.
  • The game has a lot of tunable parameters.

    Currently these are hard coded in global variables, which is bad.

    I was hoping the dictionary would have a load from file or similar.

    Is there any way in C2 to read settings from a file at runtime, so that testers/designers can modify the parameters?

    There dont seem to be any objects in C2 to read any resources (images, sprites, files, XML) from a URL.

  • There are:

    XML Entry in the Manual

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can also load Array and Dictionary object data from JSON.

  • Brilliant!

    Thanks.

  • Sorry, does anyone know the format of the json text objects required to load into a dictionary? I need to create the file using notepad or similar with a bunch of key value pairs in can then load into the dictionary object or similar.

    I know XML, but dont know json. is there a json eqiv. of the DTD of the format required to load in to a dictionary?

  • OK, forget the last post - the dictionary object cant read json files - I thought the load action would load from file, but it only can load from hand entered text at design time.

    It looks like the only route is write a some AJAX code.

    Done this, and by luck you can use a relative URL which is just the name of your json file in quotes.

    So it works - I can read in some dictionary settings via a file at runtime.

    What is the earliest time I can do this? I need to get the entire game to wait till this has done, which is a pain.

    Im using "On loading finished". Is there an eariler event I can use?

    The format of the json file is:

    {"c2dictionary":true,"data":{"test":3,"test2":2}}

    The only problem I have now is that you cant edit the file in the single file project, you have to delete it and re-add it from somehwere else if you want to change the files contents. There is an "open" option if you right click on the file in the project, but this does nothing (for me anyway).

  • OK, forget the last post - the dictionary object cant read json files - I thought the load action would load from file, but it only can load from hand entered text at design time.

    But you can enter an expression returning a string, you don't have to type it out. For example you can AJAX request a JSON project file and load that. See Using project files in Construct 2 for some examples.

    Note the JSON format used by Dictionary and Array is specific to C2 - export some JSON from empty objects and look at the result to see the format you need to use.

  • Ok, solved the not being able to open the file once imported issue - renamed it to .txt and now it opens in notepad.

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