• 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.

[JASS] buggy jass

Status
Not open for further replies.
Level 21
Joined
Mar 2, 2010
Messages
3,069
there is a problem in the jass code that cause all players except the host to drop. please check it out and upload a correct code.
function IncreaseResources takes nothing returns boolean
local unit u
local integer array i
local integer p
call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup(bj_lastCreatedGroup)
exitwhen u == null
if GetUnitTypeId(u) == 'h078' or GetUnitTypeId(u) == 'h07A' or GetUnitTypeId(u) == 'h07B' or GetUnitTypeId(u) == 'h079' or GetUnitTypeId(u) == 'n01P' or GetUnitTypeId(u) == 'n01N' or GetUnitTypeId(u) == 'n01Q' or GetUnitTypeId(u) == 'n01O' or GetUnitTypeId(u) == 'n01K' or GetUnitTypeId(u) == 'n01J' or GetUnitTypeId(u) == 'n01M' or GetUnitTypeId(u) == 'n01L' then
if GetUnitState(u, UNIT_STATE_LIFE) > 0 then
call SetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD) + udg_Gold)

set i[GetPlayerId(GetOwningPlayer(u))] = i[GetPlayerId(GetOwningPlayer(u))] + udg_Gold
endif
endif
call GroupRemoveUnit(bj_lastCreatedGroup, u)
endloop
call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup(bj_lastCreatedGroup)
exitwhen u == null
if GetUnitTypeId(u) == 'h073' or GetUnitTypeId(u) == 'h072' then
set p = 0
loop
exitwhen p > 7
if GetLocalPlayer() == Player(p) then
set udg_Temp_Point = GetUnitLoc(u)
call CreateTextTagLocBJ( "Income: +" + I2S(i), udg_Temp_Point, 0, 10, 0.00, 50.00, 0.00, 0 )
call SetTextTagVelocityBJ( bj_lastCreatedTextTag, 60.00, 90 )
call SetTextTagPermanentBJ( bj_lastCreatedTextTag, false )
call SetTextTagLifespanBJ( bj_lastCreatedTextTag, 2.50 )
call SetTextTagFadepointBJ( bj_lastCreatedTextTag, 2.00 )
call ShowTextTagForceBJ( true, bj_lastCreatedTextTag, GetForceOfPlayer(Player(p)) )
call RemoveLocation (udg_Temp_Point)
endif
set p = p + 1
endloop
endif
call GroupRemoveUnit(bj_lastCreatedGroup, u)
endloop
return false
endfunction

function InitTrig_Floating_Text takes nothing returns nothing
local trigger T = CreateTrigger()
call TriggerRegisterTimerEvent(T, udg_Interval, true)
call TriggerAddCondition( T, Condition( function IncreaseResources) )
set T = null
endfunction
 
Level 1
Joined
May 10, 2012
Messages
5
Try this

JASS:
set udg_Temp_Point = GetUnitLoc(u)

if GetLocalPlayer() == Player(p) then
call CreateTextTagLocBJ( "Income: +" + I2S(i), udg_Temp_Point, 0, 10, 0.00, 50.00, 0.00, 0 )
call SetTextTagVelocityBJ( bj_lastCreatedTextTag, 60.00, 90 )
call SetTextTagPermanentBJ( bj_lastCreatedTextTag, false )
call SetTextTagLifespanBJ( bj_lastCreatedTextTag, 2.50 )
call SetTextTagFadepointBJ( bj_lastCreatedTextTag, 2.00 )
call SetTextTagVisibility(bj_lastCreatedTextTag, true)
endif

call RemoveLocation (udg_Temp_Point)
 
Please use JASS tags to post jass, so it will come out formatted and colored.

The problem you're having is called a "desync", and occurs when the synchronization tables between players has a discrepancy. Wc3 sees this and splits the game for every player who is different. Seeing as how local integer p loops from 0 to 8, this splits the game into 9.

You can avoid this issue by not creating objects inside local blocks.

A local block looks like this:

JASS:
if GetLocalPlayer()==<player> then
    //local code
endif

And therefore the block that's causing the problem in your code is this one:

JASS:
...
if GetLocalPlayer() == Player(p) then
    set udg_Temp_Point = GetUnitLoc(u)
    call CreateTextTagLocBJ( "Income: +" + I2S(i), udg_Temp_Point, 0, 10, 0.00, 50.00, 0.00, 0 )
...
    call RemoveLocation (udg_Temp_Point)
...

To fix the issue, create the location and texttag outside the local block, and then use ShowTextTagForceBJ() inside the local block.

You should also inline those BJ functions.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Texttags can and should be created in local blocks, they are "pseudo" handles, it's perfectly safe and it helps to reach later or never the hardcoded limit of 100 texttags simultaneously.
I don't know about location, it could still be fine since you're destroying it, but it's safer to use it outside, or don't use locations at all btw.

Also i don't know if this is safe call ShowTextTagForceBJ( true, bj_lastCreatedTextTag, GetForceOfPlayer(Player(p)) )

Because i suppose it calls a ForForce and then opens a new thread each time a player is enumed.
 
JASS:
function IncreaseResources takes nothing returns boolean
    local group grp=CreateGroup()
    local unit u
    local integer array i
    local integer uID
    local integer p
    local integer playerID
    local player who
    call GroupEnumUnitsInRect(grp,bj_mapInitialPlayableArea,null)
    loop
        set u=FirstOfGroup(grp)
        exitwhen u==null
        set uID=GetUnitTypeId(u)
        if uID=='h078' or uID=='h07A' or uID=='h07B' or uID=='h079' or uID=='n01P' or uID=='n01N' or uID=='n01Q' or uID=='n01O' or uID=='n01K' or uID=='n01J' or uID=='n01M' or uID=='n01L' then
            if GetUnitState(u,UNIT_STATE_LIFE)>0 then
                set who=GetOwningPlayer(u)
                set playerID=GetPlayerId(who)
                call SetPlayerState(who,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(who,PLAYER_STATE_RESOURCE_GOLD)+udg_Gold)
                set i[playerID]=i[playerID]+udg_Gold
            endif
        endif
        call GroupRemoveUnit(grp,u)
    endloop
    call GroupEnumUnitsInRect(grp,bj_mapInitialPlayableArea,null)
    loop
        set u=FirstOfGroup(grp)
        exitwhen u==null
        set uID=GetUnitTypeId(u)
        if uID=='h073' or uID=='h072' then
            set p=0
            loop
                exitwhen p>7
                set udg_Temp_Point=GetUnitLoc(u)
                call CreateTextTagLocBJ("Income: +"+I2S(i),udg_Temp_Point,0,10,0.,50.,0.,0)
                call SetTextTagVelocityBJ(bj_lastCreatedTextTag,60.,90)
                call SetTextTagPermanentBJ(bj_lastCreatedTextTag,false)
                call SetTextTagLifespanBJ(bj_lastCreatedTextTag,2.5)
                call SetTextTagFadepointBJ(bj_lastCreatedTextTag,2.)
                if GetLocalPlayer()==Player(p) then
                    call SetTextTagVisibility(bj_lastCreatedTextTag,true)
                endif
                call RemoveLocation(udg_Temp_Point)
                set p=p+1
            endloop
        endif
        call GroupRemoveUnit(grp,u)
    endloop
    call DestroyGroup(grp)
    return false
endfunction

function InitTrig_Floating_Text takes nothing returns nothing
    local trigger T=CreateTrigger()
    call TriggerRegisterTimerEvent(T,udg_Interval,true)
    call TriggerAddCondition(T,Condition(function IncreaseResources))
    set T=null
endfunction
 
I just verified the default integer value with this:

JASS:
scope integerDefaultHasWhat initializer i
    private function i takes nothing returns nothing
        local integer array zs
        call BJDebugMsg("zs[0]="+I2S(zs[0]))
    endfunction
endscope

And therefore I think you should check the value of udg_Gold. Has this system displayed something besides 0 in the past?
 
Level 21
Joined
Mar 2, 2010
Messages
3,069
i dont know enough about jass to be able to tell anything but at least the income system itself works. it is only the display that doesnt. until anybody find the error i might continue working on the map. in order for people to better find the problem however i have included the map.
 

Attachments

  • faction war alpha12.w3x
    5.3 MB · Views: 37
Status
Not open for further replies.
Top