How do I load project file using AJAX depending on variable

Get help using Construct 2

Post » Sun Feb 26, 2017 1:08 pm

Hey everybody !

I'm trying to load a project XML file (which mean it's imported in Files folder in contruct 2) using AJAX.

But here's what make me stuck : the name of the file i load depends on the parameter i give to the function which make the AJAX request, by doing so i can't use the AJAX:Request Project File built in function since it require to choose the file before.

The XML file is supposed to contain dialogs, to load appropriate one when interacting with an NPC i got a few variable to sort my files :
► NPC.Name
► NPC.ActiveQuest
► NPC.ActiveQuestStatus


The function is : SpeakWith( NPC.Name, NPC.ActiveQuest, NPC.ActiveQuestStatus )
If i want to load the XML for the NPC "NPCtest", with ActiveQuest to "TestQuest" and ActiveQuestStatus to "starting", the file name willl be :
► "NPCtest TestQuest starting.xml"
► (Function.Param(0) &" "& Function.Param(1) &" "& Function.Param(2) &".xml")


I'm looking for a way to use AJAX to request such a file using those parameters.

I tested lots of URLs and read lots of post but still havn't found something that work.
I can post the .capx if needed.

Thanks for any help !
B
3
Posts: 5
Reputation: 185

Post » Sun Feb 26, 2017 1:16 pm

This should work: nest the XML data as values in a dictionary with keys attached that correspond to the strings you want to match, and load that data into a C2 dictionary on start. It wouldn't be too hard to write a little C2 app that could nest the data for you :)
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Sun Feb 26, 2017 1:26 pm

Yeah i like the idea, i'm testing it right now.
B
3
Posts: 5
Reputation: 185

Post » Sun Feb 26, 2017 1:36 pm

Well i got almost same problem that when using AJAX, how do i load a dicitonary saved on local disk or in project files ?
B
3
Posts: 5
Reputation: 185

Post » Sun Feb 26, 2017 2:28 pm

Oh sure that's a doddle: in the AJAX 'On Completed' condition, use the Dictionary's 'Load from JSON' action, using AJAX.LastData :)
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Sun Feb 26, 2017 4:52 pm

I believe you misunderstood my start problem, to load my file using AJAX, i need a URL to access the file because the Request Project File built in function won't let me use a string with function parameter to access my file.

Here's my problem, what's the URL leading to the project files in preview and in exported version ?
B
3
Posts: 5
Reputation: 185

Post » Sun Feb 26, 2017 5:30 pm

I found a way using NWjs, thanks anyway !
B
3
Posts: 5
Reputation: 185

Post » Sun Feb 26, 2017 11:32 pm

Be aware that reliance on NWJS means your game won't be compatible with non-desktops.

I believe I understood your problem, and that my solution is viable for it if you require browser/mobile compatibility.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 242
Reputation: 2,306

Post » Mon Feb 27, 2017 11:12 am

I believe that if you use "Request URL', URL can be the (exact) name of a project file (in a string).
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: Fenix18 and 9 guests