How do I load a random JSON file?

Get help using Construct 2

Post » Thu Apr 13, 2017 5:32 pm

I am trying to make a level generator similar to that of Spelunky. The generator for Spelunky uses premade "chunks" to generate levels. I have created a very simple level generator that I can use to create the premade chunks that will fit into the level. The levels are saved on an array as a JSON file and I have put them into my game under the "Files" folder.

I would like to be able to load one of these JSON files randomly at runtime but I am not sure if there is a way to accomplish this. The only way I know to request a JSON from the files folder is to select it by name from a dropdown menu.

Image

Is there anyway to call a JSON at random, for example, by having something like: Request File ["A"&round(random(0,10)) ]
B
17
S
4
G
4
Posts: 59
Reputation: 3,121

Post » Thu Apr 13, 2017 6:23 pm

How many json files do you have? Straight forward way is to create a function with an event for each file: if param=0, load a, param=1, load b ect... Might be a bit tedious if you have a ton of files, but you only have to do it once.

Edit: and then call the function with floor(random ()) for the parameter

Edit 2: answer below way better.
Last edited by oosyrag on Thu Apr 13, 2017 6:35 pm, edited 1 time in total.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Thu Apr 13, 2017 6:30 pm

Is there anyway to call a JSON at random, for example, by having something like:
Request File ["A"&round(random(0,10)) ]


try:

Image

Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Thu Apr 13, 2017 6:54 pm

korbaach wrote:
Is there anyway to call a JSON at random, for example, by having something like:
Request File ["A"&round(random(0,10)) ]


try:

Image

Image


This worked, thank you!
B
17
S
4
G
4
Posts: 59
Reputation: 3,121


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests