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

0 favourites
  • 14 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • I am completely new to dictionaries, JSON, etc. What I'm trying to do is this, which I'm sure is quite easy for most of you:

    I want a user to be able to load in a list of names (.txt file? I have no idea). I'm guessing those would be stored in a dictionary or something? Perhaps that's not even necessary.

    Next, I want to randomly pull one name from that list that was loaded in by the user.

    Last, is there a way to save this experience for the user to use for next time? I'd like it to retain the previous list until changed. Obviously the user could upload a new one when necessary.

    Please keep in mind that I have yet to ever publish a game or even know yet how to even make a game/save state function.

    Thank you for the guidance! I'm learning a lot, and already working on a second concept which I am finishing up before the larger game I'm working on. This has been so fun!

  • I want a user to be able to load in a list of names (.txt file? I have no idea). I'm guessing those would be stored in a dictionary or something? Perhaps that's not even necessary.

    Next, I want to randomly pull one name from that list that was loaded in by the user.

    Last, is there a way to save this experience for the user to use for next time?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I want a user to be able to load in a list of names (.txt file? I have no idea). I'm guessing those would be stored in a dictionary or something? Perhaps that's not even necessary.

    Next, I want to randomly pull one name from that list that was loaded in by the user.

    Last, is there a way to save this experience for the user to use for next time?

    Thank you for this all. I'm working on this first step, but am not sure where to start. Is loading from ajax a system command? I have a button (sprite) that I want to set as a "Load" button that when clicked, the user could load in their text file of names. From there, I would load that list into a dictionary it sounds like?

  • By the way, here is what I am building. I'm now trying to get this Load Teams button functioning from the posts above.

    simsportsgaming.com/collegefootballscenariosimulator/index.html

  • > I want a user to be able to load in a list of names (.txt file? I have no idea). I'm guessing those would be stored in a dictionary or something? Perhaps that's not even necessary.

    >

    >

    > Next, I want to randomly pull one name from that list that was loaded in by the user.

    >

    >

    > Last, is there a way to save this experience for the user to use for next time?

    >

    Thank you for this all. I'm working on this first step, but am not sure where to start. Is loading from ajax a system command? I have a button (sprite) that I want to set as a "Load" button that when clicked, the user could load in their text file of names. From there, I would load that list into a dictionary it sounds like?

    ajax plugin>request project file, to load the text file

  • Ok, struggling still to grasp all of this. I have the ajax plugin now, but when I ajax action to request "teams.txt", nothing happens when I click the sprite.

    Beyond that, I'm reading what was written here and wondering how I get this .txt file loaded into a dictionary. I have very little experience with these, so I appreciate the steps like has been done before. I'm just struggling to get this to work.

    let's say you storage them line by line in one dictionary key:namelist, so tokenat(dictionary.get("namelist"),

    floor(

    random(0,

    tokencount( dictionary.get("namelist"),newline)

    )

    )

    ,newline)

    so now we have random line's value from "namelist"

  • If you only want one random name, you don't need a dictionary.

    I made a demo project, showing several possible options:

    dropbox.com/scl/fi/2oe16nkt0w6c300gq1fbl/NamesLoadFromFile.c3p

  • If you only want one random name, you don't need a dictionary.

    I made a demo project, showing several possible options:

    https://www.dropbox.com/scl/fi/2oe16nkt0w6c300gq1fbl/NamesLoadFromFile.c3p?rlkey=4vqqojrzihooa1hyj9pj70ax5&st=48uvn2za&dl=0

    This is super helpful. Thank you. What I'm trying to do first is to allow the user to load their own .txt list of names. I thought that's what the loading of the AJAX would be doing?

  • I've tinkered a bit more, and see I can get a file to load using the FileSystem plugin. I'm a bit confused now on how to get a .txt file a user would load in and connect it in a way that it replaces the names.txt that's already in the project.

    Getting closer...

  • I've tinkered a bit more, and see I can get a file to load using the FileSystem plugin. I'm a bit confused now on how to get a .txt file a user would load in and connect it in a way that it replaces the names.txt that's already in the project.

    Getting closer...

    just place a textinput(type:multiline) for user to paste it line by line

  • You can use FileChooser object.

    + FileChooser: On changed
    -> AJAX: Request FileChooser.FileURLAt(0) (tag "tag")
    
    
  • > I've tinkered a bit more, and see I can get a file to load using the FileSystem plugin. I'm a bit confused now on how to get a .txt file a user would load in and connect it in a way that it replaces the names.txt that's already in the project.

    >

    > Getting closer...

    just place a textinput(type:multiline) for user to paste it line by line

    Why can't they just upload a .txt file with each team name on a line? This way--since they would run this simulator a few times a week--could just make updates to the .txt file only if it would be necessary. I would think entering them in one at a time for every instance of the simulator would be tedious. Maybe I misunderstood what you were saying.

  • You can use FileChooser object.

    > + FileChooser: On changed
    -> AJAX: Request FileChooser.FileURLAt(0) (tag "tag")
    
    

    I just installed FileChooser and have my sprite button now working to ask for a file. Where I get lost now is with the AJAX part. I see the "Request project file" action but I am not able to select FileChooser, nor do I see FileChooser a chooseable action within AJAX. Then what you wrote after that (.FileURLAt(0) (tag "tag"), I do not understand what any of that means.

    Thank you for the assistance!

  • howtoconstructdemos.com/using-a-sprite-to-invoke-open-file-dialog-and-a-workaround-for-filechooser-bug-c3p

    Use "AJAX Request URL" action. Also I really recommend studying the documentation and a few tutorials. Many of the questions you ask are pretty basic.

    construct.net/en/make-games/manuals/construct-3/plugin-reference/ajax

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