1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Save/Load Multiplayer Games Help

Discussion in 'Triggers & Scripts' started by thunderlazy, Nov 3, 2019.

  1. thunderlazy

    thunderlazy

    Joined:
    Dec 8, 2015
    Messages:
    5
    Resources:
    0
    Resources:
    0
    Hello guys, I have some map ideas and I would like to learn how to save/load information in multiplayer games, but i don't know anything about JASS.

    When you finish a game in Farm TD, you can type -save and the game saves a .txt file in your computer. Then you can load it later. This seems like the simplest way to me, convert information into strings then save into a .txt.

    Anyone knows how to do that? :D
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,180
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Without JASS it won't work, so the best would be you invest time inbefore to get base knowledge. Example HelpMe for some links, or just JASS Class.

    Then for the save/load you at first might want to have a look at FileIO examples. It already provides the functionality to read and write a file.

    Lastly if you might want to have some encryption to make the save code not human-readable anymore, so to fight cheating. This might be not too basic anymore. Optimal Save System 0.4 - Wc3C.net
     
  3. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,155
    Resources:
    1
    Spells:
    1
    Resources:
    1
  4. thunderlazy

    thunderlazy

    Joined:
    Dec 8, 2015
    Messages:
    5
    Resources:
    0
    Resources:
    0
    Thanks! I tested FileIO in my own way and it worked, but how do I specify which player the file will save/load to?
     
  5. thunderlazy

    thunderlazy

    Joined:
    Dec 8, 2015
    Messages:
    5
    Resources:
    0
    Resources:
    0
    yeah, but this use a lot of JASS stuff that I don't understand D:
    but maybe that FileIO and PlayerUtils libraries is what I need, I just don't know how to use it.

    how do I specify which player the file will save/load to from that: call FileIO_Write("test.txt", udg_tempstring) ?
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,180
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Read and write the File for LocalPlayer. There are for sure also tutorials about local player.

    After reading the data it will be loaded only for one player first. The new Blizzard sync functions can be used to make them sync, globally for all players.

    Tell us if you have problems with a certain step.
    For testing I would go with a simple example.
     
    Last edited: Nov 4, 2019
  7. thunderlazy

    thunderlazy

    Joined:
    Dec 8, 2015
    Messages:
    5
    Resources:
    0
    Resources:
    0
    Ok, I learned how GetLocalPlayer() function works, but i don't know how to put it in the trigger.
    (I also learned how to post my triggers lol)

    Here is a simple example of the trigger I want to do, but for LocalPlayer:
    • Save
      • Events
        • Player - Player 1 (Red) types a chat message containing -save as A substring
        • Player - Player 2 (Blue) types a chat message containing -save as A substring
        • Player - Player 3 (Teal) types a chat message containing -save as A substring
        • Player - Player 4 (Purple) types a chat message containing -save as A substring
      • Conditions
      • Actions
        • Set tempstring = (Substring((Entered chat string), 7, 999))
        • Custom script: call FileIO_Write("message.txt", udg_tempstring)


    • Load
      • Events
        • Player - Player 1 (Red) types a chat message containing -load as An exact match
        • Player - Player 2 (Blue) types a chat message containing -load as An exact match
        • Player - Player 3 (Teal) types a chat message containing -load as An exact match
        • Player - Player 4 (Purple) types a chat message containing -load as An exact match
      • Conditions
      • Actions
        • Custom script: set udg_tempstring = FileIO_Read("message.txt")
        • Game - Display to (All players) the text: tempstring
     
  8. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,180
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
  9. thunderlazy

    thunderlazy

    Joined:
    Dec 8, 2015
    Messages:
    5
    Resources:
    0
    Resources:
    0
    I think I got it, is that right?
    • save
      • Events
        • Player - Player 1 (Red) types a chat message containing -save as A substring
        • Player - Player 2 (Blue) types a chat message containing -save as A substring
        • Player - Player 3 (Teal) types a chat message containing -save as A substring
        • Player - Player 4 (Purple) types a chat message containing -save as A substring
      • Conditions
      • Actions
        • Custom script: set udg_tempplayer = GetLocalPlayer()
        • Set tempstring = (Substring((Entered chat string), 7, 999))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Triggering player) Equal to tempplayer
          • Then - Actions
            • Custom script: call FileIO_Write("player.txt", udg_tempstring)
          • Else - Actions
            • Do nothing

    • load
      • Events
        • Player - Player 1 (Red) types a chat message containing -load as An exact match
        • Player - Player 2 (Blue) types a chat message containing -load as An exact match
        • Player - Player 3 (Teal) types a chat message containing -load as An exact match
        • Player - Player 4 (Purple) types a chat message containing -load as An exact match
      • Conditions
      • Actions
        • Custom script: set udg_tempplayer = GetLocalPlayer()
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Triggering player) Equal to tempplayer
          • Then - Actions
            • Custom script: set udg_tempstring = FileIO_Read("player.txt")
            • Game - Display to (All players) the text: tempstring
          • Else - Actions
            • Do nothing
     
  10. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    3,155
    Resources:
    1
    Spells:
    1
    Resources:
    1
    The Do Nothing action is useless, just don't put anything there. I believe it's still possible to desync the game by desyncing the string table. To be sure this doesn't happen the string needs to be saved into a global that everyone can 'see'. Normally one does this by saving the string in a variable outside the local block and then only using it inside the block, but here you can't exactly do that because the LP block is what's used to load the string. Someone else will have to comment on if I'm correct or this is a non-issue.
     
  11. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,180
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    String table by clients don't need to be synced. Just be aware of this async state if you write hacky code, working directly with string table indices for example, but else one would not want to care.

    It looks right. But I would try to switch to pure Jass as soon as possible.