How do I dynamically load local files?

0 favourites
  • 4 posts
From the Asset Store
"Easy Local Notifications" enhances games with customizable local notifications.
  • Hi,

    I can use the Ajax object to load local stored files (aka "projectfiles") with the "Request project file" function. I want to load level files and I don't want to make this part "hardcoded". With this function I need to select the file to load with a selectbox and can't build the filename dynamically... Is there an option to load this files by dynamically building the filename as a string? Something like:

    Ajax.load(stage & "_" & level & ".xml")

    Any clue?

    Best,

    Benny

  • Yes, you can do that with the "Request URL" action.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 2dryas:

    To load local files through runtime I usually use AJAX's Request URL action and this url form - file:///<path to file>

    Without < and > brackets of course! C2 will search it in parent folder (if you write no full path, just filename).

    Example:

    file:///data.json

    file:///data_subfolder/aaa.txt

    file:///C:/Users/user/Documents/zzz.log

    Note: I check it with NodeWebkit ONLY! I don't know about how it works on other platforms.

  • In browser preview, the url can acces file directly by typing the filename and it's extension:

    Tag | "pick level"

    URL | level2.json

    And you can replace the url fieldname with a variable to pass a level name.

    Thanks matte for giving some clues so my project progressing flawlessly.

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