Skip to content

Condition and Filter do not have to return boolean in JASS #107

@tdauth

Description

@tdauth

JASS Filter and Condition functions do not have to return boolean or lead to exception:

call TriggerRegisterEnterRegion(CreateTrigger(), r, Filter(function s__Indexer_onEnter))

function s__Indexer_onEnter takes nothing returns nothing
    call s__Indexer_index(GetFilterUnit())
endfunction


    function s__UnitEventEx__UnitEventEx_UnitEventEx__UnitEventExCore___onEnter takes nothing returns nothing
        local unit u= GetFilterUnit()
        local integer id= (GetUnitUserData((u))) // INLINED!!
        local integer cargo_id= (GetUnitUserData((UnitEventEx__CargoUnit[id]))) // INLINED!!

            // onEnter occurs AFTER onIndex

        // The unit was dead, but has re-entered the map. Used to detect when a Meat Wagon unloads a corpse.
        if id > 0 then
            if not IsUnitLoaded(u) and UnitEventEx__CargoUnit[id] != null then
                call s__UnitEventEx__UnitEventEx_UnitEventEx__UnitEventExCore___unload(u)
            endif
        endif

        set u=null
    endfunction


call TriggerRegisterEnterRegion(CreateTrigger(), s__WorldBounds_worldRegion, Condition(function s__UnitEventEx__UnitEventEx_UnitEventEx__UnitEventExCore___onEnter))

This code leads to this exception:

Caused by: java.lang.IllegalStateException: Unable to convert com.etheller.interpreter.ast.value.DummyJassValue@51f0ac09 to boolean
	at com.etheller.interpreter.ast.value.visitor.BooleanJassValueVisitor.accept(BooleanJassValueVisitor.java:60)
	at com.etheller.interpreter.ast.value.visitor.BooleanJassValueVisitor.accept(BooleanJassValueVisitor.java:16)
	at com.etheller.interpreter.ast.value.DummyJassValue.visit(DummyJassValue.java:8)
	at com.etheller.warsmash.parsers.jass.triggers.BoolExprCondition.evaluate(BoolExprCondition.java:22)
	at com.etheller.interpreter.ast.scope.GlobalScope.queueTrigger(GlobalScope.java:698)
	at com.etheller.warsmash.viewer5.handlers.w3x.simulation.region.CRegionTriggerEnter.fire(CRegionTriggerEnter.java:26)
	at com.etheller.warsmash.viewer5.handlers.w3x.simulation.region.CRegionManager.onUnitEnterRegion(CRegionManager.java:192)
	at com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit$RegionCheckerImpl.call(CUnit.java:4427)
	at com.etheller.warsmash.viewer5.handlers.w3x.simulation.region.CRegionManager$RegionChecker.onIntersect(CRegionManager.java:78)
	at com.etheller.warsmash.viewer5.handlers.w3x.simulation.region.CRegionManager$RegionChecker.onIntersect(CRegionManager.java:62)

but works in Warcraft III. I had to change the return types of s__Indexer_onEnter and s__UnitEventEx__UnitEventEx_UnitEventEx__UnitEventExCore___onEnter to boolean and return false to fix it for Warsmash.

Warsmash should accept return type nothing in this case to emulate Warcraft's behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions