How do I dynamically load local files?

Get help using Construct 2

Post » Tue Mar 03, 2015 9:55 am

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
B
6
S
2
Posts: 19
Reputation: 1,038

Post » Tue Mar 03, 2015 1:04 pm

Yes, you can do that with the "Request URL" action.
B
55
S
28
G
18
Posts: 1,520
Reputation: 25,305

Post » Tue Mar 03, 2015 1:25 pm

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.
B
8
S
1
Posts: 72
Reputation: 606

Post » Fri Jun 19, 2015 11:29 am

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.
ImageImage
B
88
S
42
G
20
Posts: 716
Reputation: 19,715


Return to How do I....?

Who is online

Users browsing this forum: Fenix18, oosyrag, waguilar and 10 guests