HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

evil game crash

11-04-2004, 10:31 PM#1
a thing
Code:
function GoldPart2Actions takes nothing returns nothing
local integer i = 1
    set udg_GoldToBeGivenToTeam[1]=GetPlayerState(ConvertedPlayer(11),PLAYER_STATE_RESOURCE_GOLD)
    set udg_GoldToBeGivenToTeam[2]=GetPlayerState(ConvertedPlayer(12),PLAYER_STATE_RESOURCE_GOLD)
    set udg_GoldToBeGivenToTeam[2]=100 //for testing
    call msg(I2S(udg_GoldToBeGivenToTeam[1]))
    call msg(I2S(udg_GoldToBeGivenToTeam[2]))
    // find out how many players are on each team
    set udg_NumberOfPlayersOnTeam[1]=0
    set udg_NumberOfPlayersOnTeam[2]=0
    loop
        exitwhen i>5
        if PlayerIsPlaying(i) then
[b]            set udg_NumberOfPlayersOnTeam[1]=udg_NumberOfPlayersOnTeam[1]+1[/b]
        endif
        set i=i+1
    endloop
    set i = 6
    loop
        exitwhen i>10
        if PlayerIsPlaying(i) then
            set udg_NumberOfPlayersOnTeam[2]=udg_NumberOfPlayersOnTeam[2]+1
        endif
        set i=i+1
    endloop
call msg("test 1")
    // calculate how much gold each player gets
call msg("roar")
    set udg_GoldToBeGivenToTeam[1]=udg_GoldToBeGivenToTeam[1]/udg_NumberOfPlayersOnTeam[1]
call msg("roar 2")
    set udg_NumberOfPlayersOnTeam[2]=1
    set udg_GoldToBeGivenToTeam[2]=udg_GoldToBeGivenToTeam[2]/udg_NumberOfPlayersOnTeam[2]
call msg("roar 3")
    // give out the gold
call msg("test 2")
    set i = 1
call msg("test 3")
    loop
        if PlayerIsPlaying(i) then
            call AdjustPlayerStateBJ(udg_GoldToBeGivenToTeam[1],ConvertedPlayer(i),PLAYER_STATE_RESOURCE_GOLD)
        endif
        set i=i+1
    endloop
    set i=6
    loop
        exitwhen i>10
        if PlayerIsPlaying(i) then
            call AdjustPlayerStateBJ(udg_GoldToBeGivenToTeam[2],ConvertedPlayer(i),PLAYER_STATE_RESOURCE_GOLD)
        endif
        set i=i+1
    endloop
    call SetPlayerStateBJ(ConvertedPlayer(11),PLAYER_STATE_RESOURCE_GOLD,0)
    call SetPlayerStateBJ(ConvertedPlayer(12),PLAYER_STATE_RESOURCE_GOLD,0)
endfunction

//===========================================================================
function InitTrig_gold_part_2 takes nothing returns nothing
    set gg_trg_gold_part_2 = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(gg_trg_gold_part_2,10.03)
    call TriggerAddAction(gg_trg_gold_part_2,function GoldPart2Actions)
endfunction

The bold line crashes the game.
11-05-2004, 03:43 AM#2
-={tWiStÄr}=-
its good to check a line or 2 above and below the error line. sorry, but i dont know about the PlayerIsPlaying function, but i would assume it takes a player rather than the integer of the player number.
11-05-2004, 08:07 AM#3
n\/Cl34r
Does it say "1" or "i" in the arrays ? It looks wrong ...
11-05-2004, 12:45 PM#4
a thing
>.< I asked on the bent forums and someone said I fogot an exitwhen in the third loop and he was right.
11-05-2004, 03:20 PM#5
Vexorian
could be that the array is not properly initialized , but that wouldn't explain the crash
11-05-2004, 03:56 PM#6
KaTTaNa
I think you should look elsewhere for the crash, I don't think that line causes the crash.
Try replacing PlayerIsPlaying(i) with true, and see if it crashes - just in order to isolate the problem.
11-05-2004, 03:59 PM#7
Vexorian
I experienced Player() with weird values causing crashes, so PlayerIsPlaying may do too, you may replace it with a player slot status comparission