[JASS] File Writing Problem

Level 2
Joined
Aug 16, 2018
Messages
11
So I have a save code that writes save codes to a text file with preload functions, but the file writes to all players. How can I write it to only the player that typed -save?
 
Level 2
Joined
Aug 16, 2018
Messages
11
Use a Local Player clause. E.g.
JASS:
if GetLocalPlayer() == writer then
    ...
endif
Screenshot_1.png

I tried this but it didn't work
Edit: Actually it might work let me test it again
No It Doesn't work it dcs all players when you try to save
 
Last edited:
Level 33
Joined
Feb 27, 2007
Messages
4,567
Yeah, you can't locally DO something without a desync. That changes the game state for some players. What you CAN do is locally change the text of the save file for some players.

  • If - All Conditions...
    • GetLocalPlayer equal to (Triggering Playrr)
  • Then - Actions
    • Set filestring = "your long thing inside the WriteFile"
  • Else - Actions
    • Set filestring = "" //an empty string so writefile does nothing
  • Custom script call WriteFile(udg_filestring) //write it outside the localplayer if block so no desync
 

NEL

NEL

Level 6
Joined
Mar 6, 2017
Messages
113
Use GetLocalPlayers function

I'll give you an example:

JASS Version:
vJASS:
function createTextFile takes player PL returns nothing
    local string FolderName = "Site"
    local string FileName = "Sample"
    local string FileType = ".txt"
  
    if GetLocalPlayer() == PL then
        // Initialize Preload Functions
        call PreloadGenClear()
        call PreloadGenStart()
      
        // Write
        call Preload( "\n\nwww.hiveworkshop.com\n\n" )
      
        // Close It
        call PreloadGenEnd( FolderName + "\\" + FileName + "\\" + FileType )
    endif
endfunction

GUI Version:
  • createTextFile
    • Events
      • Player - Player 1 (Red) types a chat message containing -save as An exact match
      • Player - Player 2 (Blue) types a chat message containing -save as An exact match
    • Conditions
    • Actions
      • -------- ----------------------------------- --------
      • -------- Initialize Filename and Directory --------
      • Set FolderName = Site
      • Set FileName = Sample
      • -------- ----------------------------------- --------
      • Custom script: if GetLocalPlayer() == GetTriggeringTrigger() then
      • -------- ----------------------------------- --------
      • -------- Initialize Preload Functions --------
      • Custom script: call PreloadGenClear()
      • Custom script: call PreloadGenStart()
      • -------- ----------------------------------- --------
      • -------- Write --------
      • Custom script: call Preload( "\n\nwww.hiveworkshop.com\n\n" )
      • -------- ----------------------------------- --------
      • -------- Close It --------
      • Custom script: call PreloadGenEnd( udg_FolderName + "\\" + udg_FileName + ".txt" )
      • Custom script: endif
 
Level 2
Joined
Aug 16, 2018
Messages
11
Yeah, you can't locally DO something without a desync. That changes the game state for some players. What you CAN do is locally change the text of the save file for some players.

  • If - All Conditions...
    • GetLocalPlayer equal to (Triggering Playrr)
  • Then - Actions
    • Set filestring = "your long thing inside the WriteFile"
  • Else - Actions
    • Set filestring = "" //an empty string so writefile does nothing
  • Custom script call WriteFile(udg_filestring) //write it outside the localplayer if block so no desync
it works thanks +rep
 
Top