• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Simple buged Jass trigger

Status
Not open for further replies.
I am messing around with Jass scripts. What is wrong with this one? It says:
"Invalid number of arguments" in this line
JASS:
    call TriggerAddCondition( gg_trg_StaticBlink, Condition( function Trig_StaticBlink_Conditions ) )
JASS:
function Trig_StaticBlink_Conditions takes nothing returns boolean
    return true
endfunction

function Trig_StaticBlink_Func004002003001 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false )
endfunction

function Trig_StaticBlink_Func004002003002001 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING) == false )
endfunction

function Trig_StaticBlink_Func004002003002002001 takes nothing returns boolean
    return ( IsUnitAlly(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == false )
endfunction

function Trig_StaticBlink_Func004002003002002002001 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == false )
endfunction

function Trig_StaticBlink_Func004002003002002002002001 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false )
endfunction

function Trig_StaticBlink_Func004002003002002002002002 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false )
endfunction

function Trig_StaticBlink_Func004002003002002002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_StaticBlink_Func004002003002002002002001(), Trig_StaticBlink_Func004002003002002002002002() )
endfunction

function Trig_StaticBlink_Func004002003002002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_StaticBlink_Func004002003002002002001(), Trig_StaticBlink_Func004002003002002002002() )
endfunction

function Trig_StaticBlink_Func004002003002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_StaticBlink_Func004002003002002001(), Trig_StaticBlink_Func004002003002002002() )
endfunction

function Trig_StaticBlink_Func004002003002 takes nothing returns boolean
    return GetBooleanAnd( Trig_StaticBlink_Func004002003002001(), Trig_StaticBlink_Func004002003002002() )
endfunction

function Trig_StaticBlink_Func004002003 takes nothing returns boolean
    return GetBooleanAnd( Trig_StaticBlink_Func004002003001(), Trig_StaticBlink_Func004002003002() )
endfunction

function Trig_StaticBlink_Func005A takes nothing returns nothing
    call UnitDamageTargetBJ( GetTriggerUnit(), GetEnumUnit(), ( 50.00 + ( 10.00 * I2R(GetUnitAbilityLevelSwapped('A00B', GetTriggerUnit())) ) ), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING )
endfunction

function Trig_StaticBlink_Actions takes nothing returns nothing
    local group Group
    local location Point
    set Point = GetUnitLoc(GetTriggerUnit())
    set Group = GetUnitsInRangeOfLocMatching(150.00, Point, Condition(function Trig_StaticBlink_Func004002003))
    call ForGroup( Group, function Trig_StaticBlink_Func005A )
    call DestroyGroup(Group)
endfunction

//===========================================================================
function InitTrig_StaticBlink takes nothing returns nothing
    set gg_trg_StaticBlink = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_StaticBlink, EVENT_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_StaticBlink, Condition( function Trig_StaticBlink_Conditions ) )
    call TriggerAddAction( gg_trg_StaticBlink, function Trig_StaticBlink_Actions )
endfunction
 
Last edited:
1) What is the point in having a condition that just returns true? That's a waste of time unless you're tracking Trigger Evaluations.

2. Mostly Optimized

JASS:
function Blink_Evaluation takes nothing returns boolean
    local unit u = GetFilterUnit()
 
    if IsUnitType(u, UNIT_TYPE_STRUCTURE) or IsUnitType(u, UNIT_TYPE_FLYING) or IsUnitAlly(u, GetOwningPlayer(GetTriggerUnit())) or GetUnitState(u, UNIT_STATE_LIFE) > 0 or IsUnitType(u, UNIT_TYPE_MECHANICAL) or IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) then
        set u = null
        return false
    endif
 
    set u = null
    return true
endfunction
 
function Blink_Damage takes nothing returns nothing
    call UnitDamageTarget(GetTriggerUnit(), GetEnumUnit(), ( 50.00 + ( 10.00 * I2R(GetUnitAbilityLevel(GetTriggerUnit(), 'A00B')) ) ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING, WEAPON_TYPE_WHOKNOWS)
endfunction
 
function Blink_Actions takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRange(g, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), 150.00, Condition(function Blink_Evaluation))
    call ForGroup( g, function Blink_Damage )
    call DestroyGroup(g)
    set g = null
endfunction
 
//Initialize Trigger
function InitTrig_StaticBlink takes nothing returns nothing
    set gg_trg_StaticBlink = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_StaticBlink, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_StaticBlink, function Blink_Actions )
endfunction
 
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
1,084
The code can be optimized a bit more (From Bribe's post):
JASS:
function Blink_Evaluation takes nothing returns boolean
    local unit u = GetFilterUnit()
    local boolean b = IsUnitType(u, UNIT_TYPE_STRUCTURE) or IsUnitType(u, UNIT_TYPE_FLYING) or  IsUnitAlly(u, GetOwningPlayer(GetTriggerUnit())) or GetUnitState(u,  UNIT_STATE_LIFE) > 0 or IsUnitType(u, UNIT_TYPE_MECHANICAL) or  IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) //I think you should also check if the unit is alive.
    set u = null
    return b
endfunction
 
function Blink_Damage takes nothing returns nothing
    call UnitDamageTarget(GetTriggerUnit(), GetEnumUnit(), ( 50.00 + ( 10.00 * GetUnitAbilityLevel(GetTriggerUnit(), 'A00B')) ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING, WEAPON_TYPE_WHOKNOWS)
endfunction
 
Your function returns b if any of those or conditions are true. That's not what it's supposed to do. It needs to return false if any of those or conditions are true.

Also, if the GetUnitState > 0 returns false, that means the unit is dead anyway (I replaced IsUnitDeadBJ).

Edit: I'm almost positive that the I2R which you deleted from UnitDamageTarget needs to be there. I've had syntax errors from trying to calculate Integers with Reals.

@NFWar, use the code I gave you and you won't run into any problems.
 
JASS:
    return not b

Perhaps? =P

I tested it with I2R and without, it parses just fine. They are weird in what they consider integers and reals. If you directly input a value of like 2.5 and declare it as an integer, it will show an error. But if you do something like 5/2, it will be declarable as an integer without problems:
JASS:
function Whee takes nothing returns nothing
    local integer i = 5/2 //no syntax error
    local integer i2 = 7/4 //no syntax error
    local integer i3 = 2.5  //syntax error
    local integer x = i*i2 //you can declare it as an integer or a real without error
    //local real x = i*i2
endfunction

Basically, since it is multiplied by "10.00" and not "10" it is considered a real. =D
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Your function returns b if any of those or conditions are true. That's not what it's supposed to do. It needs to return false if any of those or conditions are true.

Also, if the GetUnitState > 0 returns false, that means the unit is dead anyway (I replaced IsUnitDeadBJ).
This is what happens when I don't look at the code closely.
There is a very simple fix for this though if you don't want to use not b:
JASS:
local boolean b = IsUnitType(u, UNIT_TYPE_STRUCTURE) == false and IsUnitType(u, UNIT_TYPE_FLYING) == false and IsUnitAlly(u, GetOwningPlayer(GetTriggerUnit())) == false and GetWidgetLife(u) > 0.405 and IsUnitType(u, UNIT_TYPE_MECHANICAL) == false and IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) == false //This is basically the equivalent of not b
 
Thx for help... still dont understand what is aproblem...
By cnp Bribe's trigger it show 3 errors

I am rly suck in Jass and cant understand it at all. Return what? takes what? why take? why return? Wtf is this? :S
Also all tutorials are mess, HUGE mess. It explain and I cant understand. Also Jass changing and some tutorials are useless.
 
Nah I know what the problem is. For some reason you wanted it to only target dead units. I don't know why you added that in there, but here it is without that:

JASS:
function Blink_Evaluation takes nothing returns boolean
    local unit u = GetFilterUnit()
    local boolean b = IsUnitType(u, UNIT_TYPE_STRUCTURE) or IsUnitType(u, UNIT_TYPE_FLYING) or  IsUnitAlly(u, GetOwningPlayer(GetTriggerUnit())) or GetUnitState(u,  UNIT_STATE_LIFE) <= 0 or IsUnitType(u, UNIT_TYPE_MECHANICAL) or  IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)
    set u = null
    return not b
endfunction
 
function Blink_Damage takes nothing returns nothing
    call UnitDamageTarget(GetTriggerUnit(), GetEnumUnit(), ( 50.00 + ( 10.00 * GetUnitAbilityLevel(GetTriggerUnit(), 'A00B')) ), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_LIGHTNING, WEAPON_TYPE_WHOKNOWS)
endfunction
 
function Blink_Actions takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRange(g, GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit()), 150.00, Condition(function Blink_Evaluation))
    call ForGroup( g, function Blink_Damage )
    call DestroyGroup(g)
    set g = null
endfunction
 
//Initialize Trigger
function InitTrig_StaticBlink takes nothing returns nothing
    set gg_trg_StaticBlink = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_StaticBlink, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddAction( gg_trg_StaticBlink, function Blink_Actions )
endfunction
 
I am rly suck in Jass and cant understand it at all. Return what? takes what? why take? why return?
Try deleting them and you get errors.

It's a game from 2001. Not many people were familiar with programming back then, so they weren't sure how to code their game. If something looks weird as hell, it's because it is. There's no point in writing "takes nothing returns nothing" - you shouldn't have to write that.

Return what? Return always marks the end of a function. Same as on a Mac, Return marks the end of a paragraph or the sending of data. Sometimes a function is a boolean. Like "if unit is a flyer then do actions". Well, if it's a boolean function, it needs to declare that. So it "returns boolean".

Takes what? That's only if another function is using it. Just keep on with "Takes nothing" for now.

Why take? Greedy bastards...

Why return? It's a give/take relationship.
 
Status
Not open for further replies.
Top