[solved] How do I AJAX request a variable filename?

Just started using Construct 2? Post your questions here

Post » Wed Aug 24, 2016 1:50 pm

My game has a number of levels. For each level, I need to spawn sprites in various locations. I have created json files for each my levels containing info about which sprites to spawn and their locations. When a level begins, I use its json file to populate an array "LevelData" that the game then reads from to see what to create.

My current logic looks like this:
Global number CurLevel = 1

System | On Start of Layout -> AJAX | Request level1.json(tag "currentleveldata")

AJAX | On "currentleveldata" completed -> LevelData | Load from JSON string AJAX.LastData


This all works fine but I need a way to request not a specific file like level1.json, but instead base the file name off of the level my player is currently on, like level[CurLevel].json. The dialog box for AJAX request is only giving me a drop-down menu to select files. I'm planning to include at least 50 different level setups so I really need a way to call a filename with a variable in it.
Last edited by chiuna on Wed Aug 24, 2016 2:09 pm, edited 1 time in total.
B
6
S
1
Posts: 2
Reputation: 354

Post » Wed Aug 24, 2016 2:05 pm

try with Ajax request URL : "level"&CurLevel&".json"
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Wed Aug 24, 2016 2:09 pm

korbaach wrote:try with Ajax request URL : "level"&CurLevel&".json"


You are a life-safer! thanks for the quick answer!
B
6
S
1
Posts: 2
Reputation: 354


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest