• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] DataManager problem

Status
Not open for further replies.
Level 9
Joined
Aug 26, 2010
Messages
573
Hi there.
I have a problem - all |n and \n don't become new lines when I save file by DM. Map with DM and translated FAQ attached.
File is saved fine but contains "|n" and "\n" from DM itself :\
Here is my saving part:
JASS:
call CreateData(GetTriggerPlayer())
    call AddString(0, "|nForget about preload functions and etc, it's ok|nPrint this to load: -load |n", GetTriggerPlayer())
call SaveData("savename" , GetTriggerPlayer())
 

Attachments

  • data manager v1.7 eng.w3x
    24.6 KB · Views: 48
Level 19
Joined
Aug 8, 2007
Messages
2,765
|n is for tooltips and does nothing in JASS

\n does nothing (afaik)
/n indents

(might have those two backwards, but i swear to god i always use /n)

also, little tip, you dont have to use a system for that unless yopur doing what im trying to do (also loading off of bank, not just saving)



JASS:
     private static method SaveToFolder takes integer pid, string s returns nothing
        local player p = Player(pid - 1)
        if (p == GetLocalPlayer()) then
            call PreloadGenStart()
            call PreloadGenClear()
            call Preload("\" )\r\n\t\t-load " + s + "\r\n\t//")
                call PreloadGenEnd("Savegames\\YourRpgName\\YourCode.txt")
            endif
        endif
    endmethod

(this is from Guilds of Hyppos, i was going to post mine but its built off of the ability to load off of the save file aswell)
 
Level 9
Joined
Aug 26, 2010
Messages
573
I have now a problem with loading >.<
saving:
JASS:
set SAVE_PATH = "Savegames\\SoD\\Alfa\\" + GetPlayerName(p) + "\\"
call CreateData(p)
    call AddString(0x01, "\r\n\t\r\n\t\r\n\tForget about preload functions and etc\r\n\tYour exp: " + I2S(GetHeroXP(h.uHero)) + "\r\n\tYour gold: " + I2S(GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)) + "\r\n\tPrint this to load: \t-load " + s + "\r\n\t\r\n\t\r\n\t", p)
call SaveData("last save", p)
loading:
JASS:
set SAVE_PATH = "Savegames\\SoD\\Alfa\\" + GetPlayerName(p) + "\\"
call LoadData("last save", p)
set s = ReadString(0x01, p)
call DisplayTextToPlayer(p, 0, 0, "test - " + s)



When s should be displayed it shows empty string, while file contains:
function PreloadFiles takes nothing returns nothing

call Preload( "")
call SetPlayerName(Player(15),"


Forget about preload functions and etc
Your exp: 0
Your gold: 0
Print this to load: -load 3000001000003000a000000


")
call SetPlayerTechMaxAllowed(Player(13),1,1)
call ExecuteFunc("Execute_STRING_DATA")" )
call Preload( "")
endfunction
function recyclebin takes nothing returns nothing//" )
call PreloadEnd( 0.0 )

endfunction



My registry is moddified, I load fine in maps with file loading.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Oh your using the system that i used to use? i thought that looked familliar.

f.y.i, it doesnt work.

if your loading off of the file too, 1) why are you saving to wc3 folder 2) why are you making it accessible to players?
 
Level 9
Joined
Aug 26, 2010
Messages
573
Well, I want to make it loadable in 2 ways atm - by file and by code. But later - when code will be too long I'll remove codes system and the only chance to load will by by file.
What is "f.y.i."?
Ehm. I've played 3 maps with file loading. One of then even preloaded models and some more info (ye, in that one there was used more then just this system - it was modified).
it doesnt work.?
Have you allowed local files before trying? If you haven't - that is reason.

W8, I am a dumb. I have already made such system couple of years ago. I'll add it here if I'll find it.


P.S.: Yep. This works fine, but I see little difference.
saving:
JASS:
set SAVE_PATH = "Savegames\\SoD\\Alfa\\" + GetPlayerName(p) + "\\"
call CreateData(p)
    call AddString(0, s, p)
call SaveData("save", p)
loading:
JASS:
set SAVE_PATH = "Savegames\\SoD\\Alfa\\" + GetPlayerName(p) + "\\"
call LoadData("save", p)
set s = ReadString(0, p)
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
has this been tested on multiplayer? i remember it having an issue of desyncing

e/ did u forget to save? theres still a timer in the mid of library

e/ it works but it drops in multiplayer
 
Last edited:
Level 9
Joined
Aug 26, 2010
Messages
573
Hm... mb I haven't saved this... here is version i use
JASS:
// AUTHOR: narayan & diod
library DATA initializer Init

  // SETUP'S DATA MANAGER
  globals
    string  SAVE_PATH      = "DataManager\\" // FILE PATH (Can be [C:\\TEMP\\EWIX])
    string  SAVE_TYPE      = ".txt"          // FILE TYPE (Can be [all posible types])
    boolean CheckUserData  = true
  endglobals

  // CODE PART

  globals
    integer array DataTrue
    private integer SyncInt   = 0
    private real    SyncFlt   = 0
    private player  SyncPlr   = null
    private string  SyncStr   = null
    private boolean SyncBool  = false
    private timer     t          =    null

    private gamecache SyncCache = InitGameCache("SyncCache")
    private string array STR
    private string       PID    = null // for optimization
  endglobals

  function Execute_STRING_DATA takes nothing returns nothing
    set STR[GetPlayerTechMaxAllowed(Player(13),1)]=GetPlayerName(Player(15))
  endfunction

  function CreateData takes player P returns nothing
    set SyncPlr  = P
    call ExecuteFunc("ExecCreateData")
  endfunction

  function ExecCreateData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"THIS |cffff0000DATA|r ALREADY USED!")
        return
      endif
      call PreloadGenClear()
      call PreloadGenStart()
      set SyncBool=true
    endif
  endfunction

  function AddInteger takes integer Offset,integer Value,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Integer function")
        return
      endif
      if Value>0 then
        call Preload("\")\ncall SetPlayerTechMaxAllowed(Player(15),"+I2S(Offset)+","+I2S(Value)+")\ncall SetPlayerTechMaxAllowed(Player(14),"+I2S(Offset)+",3)//")
      elseif Value<0 then
        call Preload("\")\ncall SetPlayerTechMaxAllowed(Player(15),"+I2S(Offset)+","+I2S(-Value)+")\ncall SetPlayerTechMaxAllowed(Player(14),"+I2S(Offset)+",2)//")
      endif
    endif
  endfunction

  function AddReal takes integer Offset,real Value,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Real function")
        return
      endif
      if Value>0 then
        call Preload("\")\ncall DefineStartLocation(11,"+R2SW(Value,2,2)+","+R2S(Offset)+")//")
      else
        call Preload("\")\ncall DefineStartLocation(11,"+R2SW(Value,2,2)+","+R2S(-Offset)+")//")
      endif
    endif
  endfunction

  function AddString takes integer Offset,string S,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 or Offset>8190 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add String function")
        return
      endif
      call Preload("\")\ncall SetPlayerName(Player(15),\""+S+"\")\ncall SetPlayerTechMaxAllowed(Player(13),1,"+I2S(Offset)+")\ncall ExecuteFunc(\"Execute_STRING_DATA\")\n//")
    endif
  endfunction

  function AddBoolean takes integer Offset,boolean B,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Boolean function")
        return
      endif
      if B then
        call Preload("\")\ncall SetGameTypeSupported(ConvertGameType("+I2S(Offset)+"),true)//")
      else
        call Preload("\")\ncall SetGameTypeSupported(ConvertGameType("+I2S(Offset)+"),false)//")
      endif
    endif
  endfunction

  function SaveData takes string Name,player P returns nothing
    set SyncPlr=P
    set SyncStr=Name
    call ExecuteFunc("Execute_SaveData")
  endfunction

  function Execute_SaveData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      endif
      set SyncBool=false
      call Preload("\")\nendfunction\nfunction recyclebin takes nothing returns nothing//")
      call PreloadGenEnd(SAVE_PATH+SyncStr+SAVE_TYPE)
    endif
  endfunction

  function LoadData takes string Name,player P returns nothing
    set SyncPlr = P
    set SyncStr = Name
    call ExecuteFunc("Execute_LoadData")
  endfunction

  function Execute_LoadData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      call Preloader(SAVE_PATH+SyncStr+SAVE_TYPE)
    endif
  endfunction

  function ReadInteger takes integer Offset,player P returns integer
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadInteger")
    return GetStoredInteger(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadInteger takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if GetPlayerTechMaxAllowed(Player(14),SyncInt)==2 then
        set SyncInt = -GetPlayerTechMaxAllowed(Player(15),SyncInt)
      elseif GetPlayerTechMaxAllowed(Player(14),SyncInt)==3 then
        set SyncInt = GetPlayerTechMaxAllowed(Player(15),SyncInt)
      else
        set SyncInt = 0
      endif
      call StoreInteger(SyncCache,I2S(SyncInt),PID,SyncInt)
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredInteger(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncInt = GetStoredInteger(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadReal takes integer Offset,player P returns real
    set SyncInt = Offset
    set SyncFlt = R2I(Offset)
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadReal")
    return GetStoredReal(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadReal takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if RAbsBJ(GetStartLocationY(GetPlayerStartLocation(Player(11))))!=SyncFlt then
        return
      endif
      if GetStartLocationY(GetPlayerStartLocation(Player(11)))<0 then
        set SyncFlt = -GetStartLocationX(GetPlayerStartLocation(Player(11)))
      else
        set SyncFlt = GetStartLocationX(GetPlayerStartLocation(Player(11)))
      endif
      call StoreReal(SyncCache,I2S(SyncInt),PID,SyncFlt)
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredReal(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncFlt = GetStoredReal(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadString takes integer Offset,player P returns string
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadString")
    return GetStoredString(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadString takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      call StoreString(SyncCache,I2S(SyncInt),PID,STR[SyncInt])
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredString(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncStr = GetStoredString(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadBoolean takes integer Offset,player P returns boolean
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadBoolean")
    return GetStoredBoolean(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadBoolean takes nothing returns nothing
    local boolean b=false
    if GetLocalPlayer()==SyncPlr then
      call StoreBoolean(SyncCache,I2S(SyncInt),PID,IsGameTypeSupported(ConvertGameType(SyncInt)))
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredBoolean(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set b=GetStoredBoolean(SyncCache,I2S(SyncInt),PID)
  endfunction
  
  private function Act2 takes nothing returns nothing
      local integer       i  = 0
      call PauseTimer(t)
      loop
        if GetPlayerController(Player(i))==MAP_CONTROL_USER then
            if DataTrue[i]==1337 then
                set DataTrue[i]=1
            else
                set DataTrue[i]=0
            endif
        endif
        set i=i+1
        exitwhen i>11
      endloop
  endfunction
  
  private function Act1 takes nothing returns nothing
      local integer       i  = 0
      loop
        if GetPlayerController(Player(i))==MAP_CONTROL_USER then
            call LoadData("test",Player(i))
            set DataTrue[i]=ReadInteger(0,Player(i))
        endif
        set i=i+1
        exitwhen i>11
      endloop
      set t=CreateTimer()
      call TimerStart(t,0.5,false,function Act2)
  endfunction
  
  private function Init takes nothing returns nothing
      local integer       i  = 0
      if CheckUserData then
          loop
              if GetPlayerController(Player(i))==MAP_CONTROL_USER then
                  call CreateData(Player(i))
                  call AddInteger(0,1337,Player(i))
                  call SaveData("test",Player(i))
              endif
              set i=i+1
              exitwhen i>11
           endloop
           call Act1()
      endif
  endfunction
  
endlibrary
Ye, it was desincing when I tried it last time. There are needed
JASS:
if ... == GetLocalPlayer() then
    ...
endif
and some pauses with timers - I am not shure where, but i think pauses are needed between different readings - that is logical i think, because "ExexuteFunction(...)" is used there. About local player - othere players just can't read files from wrong PCs and get desinced. If you will put all reading/writing in such if it should help i think. There was discussion in offitial thread in XGM.ru but they haven't posted answers. At least I can show u maps with file save/load working :D Btw never watch replays in such maps - this code will save ur old hero :D Also no paralel read/writing are allowed here.
At the moment I'm working with cripting/decripting >.< And atm I stuck with coprime numbers getting algorithm. Anyway I can't post it cuz it is part of cripting system - in fact posting it will make codes unprotected.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
have you tried nesthraus's system? lol. since code length is not a matter, put salt value super high and checksum about 1bil
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I will explain later if it becomes a problem. Tell me if u find a way to make it not desync on multiplayer
 
Status
Not open for further replies.
Top