• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Part of code isn't running

Status
Not open for further replies.
Level 24
Joined
Feb 28, 2007
Messages
3,480
JASS:
function GruntFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'o60D' and not IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) 
endfunction

function FarmsFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'o607' and not IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) 
endfunction

function BarracksFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'o60A' and not IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) 
endfunction

function QuestBaseFinished takes nothing returns nothing
    call QuestSetCompleted(udg_QuestBase,true)
endfunction

function QuestBaseActions takes nothing returns nothing
    local boolean BaseGrunts
    local boolean BaseFarms
    local boolean BaseBarracks
    
    call GroupEnumUnitsOfPlayer(udg_enumGrpGrunts,Player(0),Filter(function GruntFilter))
    call GroupEnumUnitsOfPlayer(udg_enumGrpFarms,Player(0),Filter(function FarmsFilter))
    call GroupEnumUnitsOfPlayer(udg_enumGrpBarracks,Player(0),Filter(function BarracksFilter))
    if (not IsQuestItemCompleted(udg_QuestBaseGrunts)) then
        if CountUnitsInGroup(udg_enumGrpGrunts) == 3 then
            set BaseGrunts = true
            call QuestItemSetCompleted(udg_QuestBaseGrunts,true)
            if (BaseFarms == true and BaseBarracks == true) then
                call BJDebugMsg("Test")
                call QuestBaseFinished()
            else
                call BJDebugMsg("Fail")
            endif                      
        endif
    endif
    if (not IsQuestItemCompleted(udg_QuestBaseFarms)) then
        if CountUnitsInGroup(udg_enumGrpFarms) == 2 then
            set BaseFarms = true
            call QuestItemSetCompleted(udg_QuestBaseFarms,true)
        endif
    endif
    if (not IsQuestItemCompleted(udg_QuestBaseBarracks)) then
        if CountUnitsInGroup(udg_enumGrpBarracks) == 1 then
            set BaseBarracks = true
            call QuestItemSetCompleted(udg_QuestBaseBarracks,true)
        endif
    endif
endfunction

function InitTrig_QuestBaseComplete takes nothing returns nothing
    set gg_trg_QuestBaseComplete = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(gg_trg_QuestBaseComplete,Player(0),EVENT_PLAYER_UNIT_CONSTRUCT_FINISH,null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_QuestBaseComplete, Player(0),EVENT_PLAYER_UNIT_TRAIN_FINISH,null)
    call TriggerAddAction(gg_trg_QuestBaseComplete, function QuestBaseActions )
endfunction

The problem is that this part never runs:
JASS:
if (BaseFarms == true and BaseBarracks == true) then
    call BJDebugMsg("Test")
    call QuestBaseFinished()
else
    call BJDebugMsg("Fail")
endif

I have no clue to as what the problem could be, so any help would be welcome.
 
Level 14
Joined
Nov 23, 2008
Messages
187
The problem is in that there are no values assigned to local variables before "that part of code". This variant should work:

JASS:
function QuestBaseActions takes nothing returns nothing
    // setting initial values
    local boolean BaseGrunts   = false
    local boolean BaseFarms    = false
    local boolean BaseBarracks = false

    call GroupEnumUnitsOfPlayer(udg_enumGrpGrunts,Player(0),Filter(function GruntFilter))
    call GroupEnumUnitsOfPlayer(udg_enumGrpFarms,Player(0),Filter(function FarmsFilter))
    call GroupEnumUnitsOfPlayer(udg_enumGrpBarracks,Player(0),Filter(function BarracksFilter))
    
    if (not IsQuestItemCompleted(udg_QuestBaseGrunts)) then
        if CountUnitsInGroup(udg_enumGrpGrunts) == 3 then
            set BaseGrunts = true
            call QuestItemSetCompleted(udg_QuestBaseGrunts,true)
        endif
    endif
    
    if (not IsQuestItemCompleted(udg_QuestBaseFarms)) then
        if CountUnitsInGroup(udg_enumGrpFarms) == 2 then
            set BaseFarms = true
            call QuestItemSetCompleted(udg_QuestBaseFarms,true)
        endif
    endif
    
    if (not IsQuestItemCompleted(udg_QuestBaseBarracks)) then
        if CountUnitsInGroup(udg_enumGrpBarracks) == 1 then
            set BaseBarracks = true
            call QuestItemSetCompleted(udg_QuestBaseBarracks,true)
        endif
    endif
    
    // checking for all quest requirements
    if (BaseFarms and BaseBarracks and BaseGrunts) then
        call BJDebugMsg("Test")
        call QuestBaseFinished()
    else
        call BJDebugMsg("Fail")
    endif
endfunction
 
Status
Not open for further replies.
Top