Boolean Compile Error

D

dArKzEr0

Guest
Code:
call ForGroupBJ( GetUnitsInRangeOfLocMatching( 600, casterPoint, Condition(GetBooleanAnd( (IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(casterUnit))==true) , (IsUnitAliveBJ(GetFilterUnit())==true))) ))

I'm getting a compile error "Invalid argument type (boolean)" and I can't figure out why, anyone care to provide a bit of insight?

-darks
 
D

Dino.pl

Guest
It must be Condition(function xxx)
And function xxx must return a boolean.

And it's faster to use and instead of GetBooleanAnd
Code:
function GetBooleanAnd takes boolean valueA, boolean valueB returns boolean
    return valueA and valueB
endfunction
And you don't have to write ==true.
And it's much faster to use
Code:
GetUnitState(whichUnit, UNIT_STATE_LIFE) > 0
instead of
Code:
IsUnitAliveBJ
Hmm, was I helpful?
 
D

dArKzEr0

Guest
Ya, thanks a lot. Can you have locals in a function defined before the boolean function inside the function?

Code:
function WithinRangeAndAlive takes nothing returns boolean
   return GetBooleanAnd(IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer([I][B]casterUnit[/B][/I])), IsUnitAliveBJ(GetFilterUnit())
endfunction

If not, how do I get around that?

Also, could you explain (if you know) why you have to use a function (why my method didn't work)?

-darkz
 

SFilip

Gone but not forgotten
Reaction score
633
because Condition must take function as its parameter i suppose.

> And you don't have to write ==true.
you dont have to, but its recommended that you do. acehart and phyrex1an mentioned that some functions dont work well if you dont use == true or == false.
 

emjlr3

Change can be a good thing
Reaction score
395
if in the same function, something like

Code:
IsUnitEnemy(unit,player)

works fine

however if its in another function, and u use it as a boolexpr

you should do

Code:
IsUnitEnemy(unit,player)==true/false

it bugs sometimes, duno y

that is my general rule of thumb
 
D

Dino.pl

Guest
> acehart and phyrex1an mentioned that some functions dont work well if you dont use == true or == false.
But some do.

> Ya, thanks a lot. Can you have locals in a function defined before the boolean function inside the function?
You can have locals at the beggining of every function.
 

SFilip

Gone but not forgotten
Reaction score
633
> But some do.
is it so hard to simply write == true every time you check some boolean? i think it isn't.
 
D

Dino.pl

Guest
> is it so hard to simply write == true every time you check some boolean? i think it isn't.
I don't write it in PHP, so I don't write it in JASS.
If something doesn't work, I add == true.
 
D

dArKzEr0

Guest
Dino.pl said:
> Ya, thanks a lot. Can you have locals in a function defined before the boolean function inside the function?
You can have locals at the beggining of every function.

I think you misunderstood, or maybe I wasn't clear.
What I meant was, can you use a local variable in the boolexpr that is defined in the main function?

function
boolexpr( localvariable )
endfucntion

function
local localvariable
endfunction

I assume the answer is no. What I'm looking for is an alternative. Can I set the function to "take unit" so that I call "WithinRangeAndAlive(casterUnit)" and it uses the local where it's supposed to be? I hope I'm making sense...

Forgive the noobness, I know a fair bit of Java, but this is the first time I attempt to use JASS, and the syntax is not nearly as nice.

-darkz
 

SFilip

Gone but not forgotten
Reaction score
633
Dino.pl said:
> is it so hard to simply write == true every time you check some boolean? i think it isn't.
I don't write it in PHP, so I don't write it in JASS.
If something doesn't work, I add == true.
PHP != JASS
its diffrent. i dont use == true in php, i dont use = true in pascal yet i do in jass. your choice though...better to write it always than making yourself wonder one day why the hell this condition wont work.
 
D

dArKzEr0

Guest
I tried this:

Code:
function IsEnemy takes unit casterUnit returns boolean
   return ( IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(casterUnit))==true)
endfunction

function IsAlive takes nothing returns boolean
   return ( IsUnitAliveBJ(GetFilterUnit())==true )
endfunction

function IsEnemyAndAlive takes unit casterUnit returns boolean
   return GetBooleanAnd(IsEnemy(casterUnit), IsAlive())
endfunction

function
   local unit casterUnit = XXXX
   ...
   call ForGroupBJ(GetUnitsInRangeOfLocMatching( 600, casterPoint, Condition(IsEnemyAndAlive(casterUnit)) ))
   ...
endfunction

And I'm getting the same "Invalid argument type (boolean)" compile error.

-darkz
 
D

Dino.pl

Guest
> What I meant was, can you use a local variable in the boolexpr that is defined in the main function?
Why don't you test yourself?

> I assume the answer is no.
Gratz!

> What I'm looking for is an alternative. Can I set the function to "take unit" so that I call "WithinRangeAndAlive(casterUnit)" and it uses the local where it's supposed to be?
If you mean something like that, the answer is "yes, you can!" (but again, why don't you test yourself?)
Code:
function saySoaD takes string s returns nothing
    call BJDebugMsg(s)
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing 
    local string txt = "System of a Down rox!"
    call saySoaD(txt)
endfunction

function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_001, 2 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
EDIT:
> And I'm getting the same "Invalid argument type (boolean)" compile error.
Dino.pl said:
It must be Condition(function xxx)
And function xxx must return a boolean.
It must be
Condition(function IsEnemyAndAlive(casterUnit))
, not
Condition(IsEnemyAndAlive(casterUnit))
.
 
D

dArKzEr0

Guest
Dino.pl said:
> What I meant was, can you use a local variable in the boolexpr that is defined in the main function?
Why don't you test yourself?

> I assume the answer is no.
Gratz!

> What I'm looking for is an alternative. Can I set the function to "take unit" so that I call "WithinRangeAndAlive(casterUnit)" and it uses the local where it's supposed to be?
If you mean something like that, the answer is "yes, you can!" (but again, why don't you test yourself?)
Code:
function saySoaD takes string s returns nothing
    call BJDebugMsg(s)
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing 
    local string txt = "System of a Down rox!"
    call saySoaD(txt)
endfunction

function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_001, 2 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction


Hmm... seems your genius-like wit was about 20 seconds too late. I tested everything myself. Gratz! to me, but it still isn't working.

-darkz

Edit://
>> And I'm getting the same "Invalid argument type (boolean)" compile error.
>Quote:
>Originally Posted by Dino.pl
>It must be Condition(function xxx)
>And function xxx must return a boolean.

Dude, I tried doing that. IsEnemyAndAlive(unit) is a function.
 

SFilip

Gone but not forgotten
Reaction score
633
return GetBooleanAnd(IsWithinRange(casterUnit), IsAlive())
i dont think you can call it that way...try
return GetBooleanAnd(Condition(function IsWithinRange), Condition(IsAlive))
yet the problem here is that you cant transfer casterUnit. however you can define it in that function as long as its a part of the original trigger.
local casterUnit = GetSpellAbilityUnit()
 
D

Dino.pl

Guest
Don't listen to SFilip, it doesn't make sense :)
(look at my edit)
 
D

dArKzEr0

Guest
@SFilip
I tried what you said and a few variations of it and I got a plethora of syntax errors each time.

@Dino.pl
I tried this:

Code:
function IsEnemy takes unit casterUnit returns boolean
   return ( IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(casterUnit))==true)
endfunction

function IsAlive takes nothing returns boolean
   return ( IsUnitAliveBJ(GetFilterUnit())==true )
endfunction

function IsEnemyAndAlive takes unit casterUnit returns boolean
   return GetBooleanAnd(IsEnemy(casterUnit), IsAlive())
endfunction

function
   ...
   local unit casterUnit
   ...
   call ForGroupBJ(GetUnitsInRangeOfLocMatching( 600, casterPoint, Condition(function IsEnemyAndAlive(casterUnit)) ))
   ...
endfunction

and I got: " Expected ' " compile error

So I changed the main function to:

Code:
function
   ...
   local unit casterUnit
   ...
   call ForGroupBJ(GetUnitsInRangeOfLocMatching( 600, casterPoint, Condition(function 'IsEnemyAndAlive(casterUnit)') ))
   ...
endfunction

and I got: " Expected a function name " compile error

I misunderstood earlier because I thought you were using "function" as a variable.

-darkz

Edit://
I also tried this:

Code:
function IsEnemy takes nothing returns boolean
   local unit casterUnit = GetSpellAbilityUnit()
   return ( IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(casterUnit))==true)
endfunction

function IsAlive takes nothing returns boolean
   return ( IsUnitAliveBJ(GetFilterUnit())==true )
endfunction

function IsEnemyAndAlive takes nothing returns boolean
   return GetBooleanAnd(IsEnemy(), IsAlive())
endfunction

function
   ...
   local unit casterUnit
   ...
   call ForGroupBJ(GetUnitsInRangeOfLocMatching( 600, casterPoint, Condition(function 'IsEnemyAndAlive') ))
   ...
endfunction

Edit2://
and still got "expected function name"

So I changed the main function to:
Code:
function
   ...
   local unit casterUnit
   ...
   call ForGroupBJ(GetUnitsInRangeOfLocMatching( 600, casterPoint, Condition(function IsEnemyAndAlive) ))
   ...
endfunction

and I got "invalid number of arguments"

This damned boolexpr does not like me.
 
D

Dino.pl

Guest
You have no function name in your main function :D
And you don't need the '
 
D

dArKzEr0

Guest
dArKzEr0 said:
So I changed the main function to:
Code:
function
   ...
   local unit casterUnit
   ...
   call ForGroupBJ(GetUnitsInRangeOfLocMatching( 600, casterPoint, Condition(function IsEnemyAndAlive) ))
   ...
endfunction

and I got "invalid number of arguments"

This damned boolexpr does not like me.

I checked the arguments of GetUnitsInRangeOfLocMatching() and I have them right.

"This damned boolexpr does not like me."

-darkz
 

SFilip

Gone but not forgotten
Reaction score
633
lol i though you just weren't writing the function's name here...well it must be
function <name> takes nothing returns nothing
in order to work

and if return GetBooleanAnd(IsEnemy(casterUnit), IsAlive()) works then return GetBooleanAnd(IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(casterUnit))==true, IsUnitAliveBJ(GetFilterUnit())==true) should work aswell. then you will only need one function.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top