HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Host/Single Player Check Problems

11-16-2008, 01:02 AM#1
ClichesAreSt00pid
Yay new random issues that make no sense.

In single player the SaveGameCache() apparently somehow returns false as if it's multiplayer when it's not, then it just get's stuck at "set t=GetHostId()". I really do not understand it. It was working perfectly before and I don't remember even touching it and now it's totally screwed up and doesn't work at all. I played on LAN and it still does not work.

Here's the trigger:

Collapse JASS:
library CheckHost initializer Init requires GlobalFuncs

    globals
        private gamecache GC
    endglobals
    
    private function GameCache takes nothing returns gamecache
        if (GC == null) then
            set GC = InitGameCache("hostcheck.w3v")
        endif
        
        return GC
    endfunction

    private function GetHostId takes nothing returns integer
        call StoreInteger(GameCache(), "missionKey", "key", GetPlayerId(GetLocalPlayer()) + 1)
        
        call TriggerSyncStart()
        call SyncStoredInteger(GameCache(), "missionKey", "key")
        call TriggerSyncReady()
        
        return GetStoredInteger(GameCache(), "missionKey", "key") - 1
    endfunction

    public function GetHost takes nothing returns nothing
        local integer array id
        local real array latency
        local integer max = 0
        local integer t = 0
        local integer i = 0
        
        local timer T = CreateTimer()
        call TimerStart(T,20.,false,null)
        
        set HOST = null
        
        loop
        exitwhen i > 11
            set id[i] = 0
            set i = i + 1
        endloop
        set i = 0
        
        loop
        exitwhen i > 5
            set latency[i]=TimerGetElapsed(T)
            set t = GetHostId() // Stuck here so it's probably in the GetHostId() function
            set latency[i] = TimerGetElapsed(T)-latency[i]
            
            set id[t] = id[t] + 1
            if id[t] > id[max] then
                set max = t
            endif
            
            set i = i + 1
            call PauseTimer(T)
            call PolledWait2(1.) 
            call ResumeTimer(T)
        endloop
        
        set HOST = Player(max)
        set LATENCY = (latency[1]+latency[2]+latency[3]+latency[4]+latency[5])/5.
        
        call ClearTextMessages()
        call DisplayTimedTextToForce(bj_FORCE_ALL_PLAYERS,10.,"Host: "+GetPlayerName(HOST))
        call DisplayTimedTextToForce(bj_FORCE_ALL_PLAYERS,10.,"Latency: "+I2S(R2I(LATENCY*1000)))
        call StartSound(SOUND_RADIO_FEEDBACK_C_1)
        call TriggerRegisterPlayerChatEvent(CommandKick_T,HOST,"-kick",false)
        
        call FlushStoredMission(GameCache(),"missionKey")
        call PauseTimer(T)
        call DestroyTimer(T)
        set T = null
    endfunction

    private function Actions takes nothing returns nothing
        local gamecache gc=InitGameCache("cheatcheck.w3v")
        call StoreInteger(gc,"test","test",9)
        
        if SaveGameCache(gc) then
            set SINGLE_PLAYER = true
            set HOST = GetLocalPlayer()
            call DisplayTimedTextToForce(bj_FORCE_ALL_PLAYERS,10.,"\nThe current game is single player.")
        else
            call GetHost()
        endif
        
    endfunction

    
    // Initializer
    private function Init takes nothing returns nothing
        local trigger T = CreateTrigger()
        call TriggerRegisterTimerEventSingle(T,3.0)
        call TriggerAddAction(T,function Actions)
    endfunction
    
endlibrary
11-16-2008, 06:57 PM#2
ClichesAreSt00pid
Alright I think it's supposed to stop there in single player. The real problem I think is that SaveGameCache() is returning false in single player for some reason.

So the question I suppose is: Why can't I save a game cache? I don't know why someone wouldn't be able to.

I put the trigger in a test map and it worked fine. Something in another trigger I guess is making it unable to, but I don't know what.

Edit: I did a debug check and apparently the variable is nulled. Any idea why a game cache would be nulled?
11-16-2008, 09:33 PM#3
Jazradel
There are bugs that are caused by having 256 saved gamecaches in single player.

I don't know if thats one of them, but it seems likely.


Couldn't you just check if there's only one player, rather than using SaveGameCache()?
SaveGameCache() probably just returns false.
11-16-2008, 10:01 PM#4
ClichesAreSt00pid
Then you can't play alone on LAN/bnet.

I'm pretty sure I don't have more than 5 game caches including the ones in the trigger.
11-16-2008, 10:44 PM#5
Captain Griffen
Try:

Collapse JASS:
    private function GameCache takes nothing returns gamecache
        if (GC == null) then
            call FlushGameCache(InitGameCache("hostcheck.w3v"))
            set GC = InitGameCache("hostcheck.w3v")
        endif
        
        return GC
    endfunction
11-17-2008, 01:08 AM#6
ClichesAreSt00pid
Thanks for the tip but it didn't work. Same outcome.

I tried replacing gc with GameCache() and it would just cut off completely at the "storeinteger" part. I tried flushing gc before initializing it and that did nothing.

Edit: Okay the problem has to do with all the game caches simply not working period. I recall this happening 1-2 years ago but I don't remember what the cause and fix was. If you know any reasons why game caches could be screwed up like this then let me know.
11-17-2008, 12:06 PM#7
Captain Griffen
256 limit. Across the profile.
11-17-2008, 09:21 PM#8
ClichesAreSt00pid
What's across the profile?

And there's only like 5 game caches. Is there anything that could cause problems with them?

This is bugging me :o.
11-17-2008, 09:39 PM#9
Captain Griffen
For the profile, not for the map.
11-17-2008, 10:42 PM#10
Jazradel
Everytime you play a map single player that uses InitGameCache('X'), it creates a new game cache in your profile.

Your profile can only have 256 game caches before things bug.
11-18-2008, 12:09 AM#11
ClichesAreSt00pid
So I just gotta make sure I flush them all?

And how do I clear it now then?
11-18-2008, 12:29 AM#12
Captain Griffen
Try it with a new profile, see if that is the problem.
11-18-2008, 12:46 AM#13
ClichesAreSt00pid
Yeah I tested it on LAN and the game caches seem to be working there.

YES it's working now! Thank god I love you guys. I wish I could +100 rep and give cookies.

Thanks for your patience especially ^.^. I've learned a good amount today.
12-18-2008, 05:03 PM#14
Themis
Collapse JASS:
    globals
        private gamecache GC
    endglobals
    
    private function GameCache takes nothing returns gamecache
        if (GC == null) then
            call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "GC == null" )
            set GC = InitGameCache("hostcheck.w3v")
        else
            call DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "GC != null" )
        endif
        
        return GC
    endfunction

The issue here in your code is that you should do:

Collapse JASS:
    globals
        private gamecache GC = null
    endglobals