0 Favourites

How do I load a random JSON file?

  • 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.

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

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • [quote:1u15tdmy]Is there anyway to call a JSON at random, for example, by having something like:

    Request File ["A"&round(random(0,10)) ]

    try:

  • [quote:7kfav6xw]Is there anyway to call a JSON at random, for example, by having something like:

    Request File ["A"&round(random(0,10)) ]

    try:

    This worked, thank you!

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