How do I Load List of Names to Randomly Pull From (JSON?)?

0 favourites
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • FileChooser Click action only emulates a click on this object. You still need to wait for the user to pick the file they want to load.

    So you can't put AJAX Request immediately after that. You need to use "On changed" trigger and request the selected FileURL, not "teams.txt":

  • Ok, I have this all set but am stuck at the "do your own thing part" haha. That's precisely my issue! I'm so close, but while I have it setup to allow a user to load in their own teams.txt file, it doesn't seem to be connecting/replacing the existing teams.txt as when I run the simulator again after loading the teams.txt, the names are not changing.

  • What do you mean by "replace the existing teams.txt"? You can't physically replace a project file with some other file in runtime.

    What you can do is ignore the project file and load the data from the file provided by user.

    If you want to save the data between sessions, you will need to save the list of teams (either from the project or provided by the player), say, in Local Storage. Then the logic could be something like this:

    On start of the game:
    
     If Local Storage has saved data -> Load teams from Local Storage
     Else: 
     ...Ask if the player wants to use standard teams
     ...If yes -> Load from teams.txt
     ...Else -> show FileChooser dialogue and load from selected file
    
    
    At the end of the session/level -> Save current teams in Local Storage
    
  • Yeah, this should work. I'm having trouble following which plugins would contain these parts to get it up and running. I like what you laid out though.

  • Still hoping to get some help on getting this setup.

    Right now, I made a pop-up that gives the user two options

    Load default teams (which I will just store in a variable string)

    Load list

    If they select load list, the filechooser pops open for them. Then I'm just not sure how to bring in their list.txt and have it come in as an option to use instead of the default teams.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You receive the file URL from FileChooser and you can request it with AJAX. (see the screenshot in my earlier comments).

    Once you get the response from AJAX you can do whatever you want with this data. Say, simply store it in a string variable:

    Set teamsVar to AJAX.LastData

    Or maybe you want to break it into lines and store all teams in an array:

    For "n" from 0 to tokencount(AJAX.LastData, newline)
    .. Array push back tokenat(AJAX.LastData, loopindex, newline)
    
  • Getting close...If I want to replace my existing [choose("Team1", "Team2", etc.)] with this list from the "teams" tag or (which I've set to the TeamsData variable as well), is that possible. I know the choose command isn't going to work with this, so trying to find the best workaround.

  • I feel as though I'm at this stage, but I hardly understand Construct 3 code let alone psuedo Construct 3 code.

    For "n" from 0 to tokencount(AJAX.LastData, newline)

    .. Array push back tokenat(AJAX.LastData, loopindex, newline)

    The screenshots have been super helpful. I'm also worried about using AJAX.LastData as I'm using that now in this project for a few different things, like team names (this situation we're discussing) but then also for a collection of player positions.

  • I made a demo project for you some time ago, did you see it?

    construct.net/en/forum/construct-3/how-do-i-8/load-list-names-randomly-pull-184710

    It demonstrates how to load a list of names (teams) into an array, a dictionary, or a variable. And how to get a random name.

    The screenshots have been super helpful. I'm also worried about using AJAX.LastData as I'm using that now in this project for a few different things, like team names (this situation we're discussing) but then also for a collection of player positions.

    This is why I told you in another post not to use "Wait 4 seconds" before accessing AJAX.LastData!

    AJAX has tags for this exact reason, to allow multiple requests running at the same time and distinguish between them. Once an AJAX request is completed, you need to immediately copy its data somewhere - into a variable/array etc. Because another request will replace AJAX.LastData

  • The timings shouldn't impact what I'm trying to do, but I understand. The timings are because of some other reasons. I'm sure it's not ideal design, so I'd love to learn a better way to organize my project. Happy to share if you're interested. I want to learn! I will take a look again at the demo. Thank you!

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