• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] File Writing Problem

Status
Not open for further replies.
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 38
Joined
Feb 27, 2007
Messages
4,951
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
 
Status
Not open for further replies.
Top