• 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] Problema with local player on load

Status
Not open for further replies.
Level 4
Joined
Mar 16, 2009
Messages
34
hi guys and thanks for your help

i was using File I/O to save data from players for my game,
but load sistem has a problem: global varibles loades only are saved for local player, so i have diferen values of the same global variable for each player, how i can fix it?


This is the load script (vjass)
JASS:
struct Load extends array
    private static string array data2
    private static string array data1
    private static string array datac


    private static method checkData takes nothing returns nothing
        local integer i = 0
        local integer m = 0
        local integer x = 0
        local boolean fail = false
 
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10, "  Cheking Data")
        if (data1[1] != null) then
        
                set m = 0
                set i = 0
                loop       
                    set m = i - S2I (data2[10])//el loop - la clave
                    if (m <= -1)then 
                        set m = m + 11
                    endif
                    set datac[i] = data1[m]
                   set i = i + 1 
                   exitwhen data1[i] == null
               endloop
            set i = 0               
            loop //CompareBackUp
                set i = i + 1
                exitwhen i == 10
                if ( datac[i] != data2[i]) then
                    set fail = true
                endif
            endloop
            set i = 2
            set m = 0
            loop //Comprovar si el codigo fue alterado
                set m = m + S2I(data2[i])
                set i = i + 1
                exitwhen i == 9
            endloop
            if (S2I(data2[i]) != m) then                //Comprovar si el codigo fue alterado
                set fail = true
            endif
            if (fail == false) then
                 set x = GetConvertedPlayerId(GetLocalPlayer())
                call DisplayTimedTextToForce( GetPlayersAll(), 10.00,( GetPlayerName(GetLocalPlayer()) + " _PlayerID: "+ I2S(x)))
                call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"  PlayerID: "+ I2S(x))
                call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"  Loading...")
                set udg_OldPlayer[x] = true
                set udg_Stats_Name[x] = data2[0]
                call SetPlayerStateBJ( ConvertedPlayer(x), PLAYER_STATE_RESOURCE_GOLD, S2I( data2[2]) ) //Gold
                set udg_Stat_Player_Victory[x] = S2R( data2[3]) //wins
                set udg_Stat_Player_defeats[x] = S2R( data2[4]) //loses
                set udg_Stat_Player_Kills[x] = S2I( data2[5]) //kills
                set udg_Stat_Player_Deads[x] =  S2I( data2[6]) //deads
                set udg_Stat_Player_Pre_points[x] =  S2I( data2[7]) //Points
                set udg_Stat_Player_Playedtime[x] =  S2I( data2[8]) //Time
                call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Acount Loaded!")
            else
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Your acount has been corrupted!") 
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"Your Acount has been reset")
            set udg_OldPlayer[x] = false
            call AdjustPlayerStateBJ( 550, GetLocalPlayer(), PLAYER_STATE_RESOURCE_GOLD )
            set udg_Stat_Player_Victory[x] = 1.00 //wins
            set udg_Stat_Player_defeats[x] = 1.00 //loses
            set udg_Stat_Player_Kills[x] = 0 //kills
            set udg_Stat_Player_Deads[x] =  1 //deads
            set udg_Stat_Player_Pre_points[x] =  10 //Points
            set udg_Stat_Player_Playedtime[x] =  1 //Time
            endif
        else
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"New Player detected")
            set udg_OldPlayer[x] = false
            call AdjustPlayerStateBJ( 550, GetLocalPlayer(), PLAYER_STATE_RESOURCE_GOLD )
            set udg_Stat_Player_Victory[x] = 1.00 //wins
            set udg_Stat_Player_defeats[x] = 1.00 //loses
            set udg_Stat_Player_Kills[x] = 0 //kills
            set udg_Stat_Player_Deads[x] =  1 //deads
            set udg_Stat_Player_Pre_points[x] =  10 //Points
            set udg_Stat_Player_Playedtime[x] =  1 //Time
            set udg_Ava_Activated[x] =  true  //Help
        endif
    endmethod
    

    
    private static method read takes nothing returns nothing
        local File file = File.open("InfinitySquared", "InfinitySaved", File.Flag.READ)
        local integer i = 0
        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"  Reading data ")
        loop
            set data2[i] = file.read()
            exitwhen null == data2[i]
            set i = i + 1
        endloop
        call file.close()
  
    endmethod
    
    
    
    private static method readcc takes nothing returns nothing
        local File file = File.open("InfinitySquared", "InfinitySavedBackUp", File.Flag.READ)
        local integer i = 0
        loop
            set data1[i] = file.read()
            exitwhen null == data1[i]
            set i = i + 1
        endloop
        call file.close()
  
    endmethod
    
    
    
    private static method init takes nothing returns nothing
        call DestroyTimer(GetExpiredTimer())
        if (not File.enabled) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"You do not have local files enabled at the moment")
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,"To enable local files, please run: " + File.localFileScriptName)
        else
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,10,"Loading Your Acount...")            
            call read()
            call readcc() 
            call checkData()
        endif
    endmethod
    
    
    
    private static method onInit takes nothing returns nothing
        call TimerStart(CreateTimer(),.1,false,function thistype.init)
    endmethod
endstruct

the map is attached.

pd: sorry for my bad english
 

Attachments

  • Infinity2 A 3.6hb.w3x
    3 MB · Views: 47
  • File OI.txt
    14.7 KB · Views: 93
  • Script Save.txt
    3.3 KB · Views: 63
  • Script Load.txt
    5.6 KB · Views: 64
Status
Not open for further replies.
Top