Adding onto a local integer?

Beetlebomb

New Member
Reaction score
43
Where do I add this? I'm guessing since it's filtered I dont want to put it with the Add function.
 

Beetlebomb

New Member
Reaction score
43
Well here, let me just show you what I got. I'm very confused. I dont really have a unit group filter function(that I know of ><).

JASS:
function Cond takes nothing returns boolean
    return GetSpellAbilityId() == &#039;AHtc&#039; 
endfunction

globals
    integer i = 0
endglobals

function Count takes nothing returns boolean
    return ( IsUnitDeadBJ(GetEnumUnit()) == true )
endfunction

function Add takes nothing returns nothing
    set i = i + 1
endfunction

function kill2 takes nothing returns nothing
    call KillUnit( GetEnumUnit())
endfunction

function Trig_Remove_Archers_Actions takes nothing returns nothing
    local group g = GetUnitsOfTypeIdAll(&#039;earc&#039;)
    call ForGroupBJ(g, function Count)
    call ForGroup(g, function Add)
    call GetWidgetLife (GetFilterUnit () &gt; 0.405 )
    call ForGroup(g, function kill2)
    call DestroyGroup(g)
    call DisplayTextToForce(GetPlayersAll(), &quot;Number of Archers Killed: &quot;+I2S(i) )
    set i = 0
endfunction


//===========================================================================
function InitTrig_Remove_Archers takes nothing returns nothing
    set gg_trg_Remove_Archers = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Remove_Archers, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Remove_Archers, Condition(function Cond) )
    call TriggerAddAction( gg_trg_Remove_Archers, function Trig_Remove_Archers_Actions )
endfunction


Also the widget function gave me a syntax error until I moved a ) to the outside, but it still tells me that I can't convert a boolean into a widget and that comparing the order/size of 2 variables on works on reals and integers.
 

Beetlebomb

New Member
Reaction score
43
I still get the same JassHelper Errors as before. No Syntax Errors though. That alright?

JASS:
function Cond takes nothing returns boolean
    return GetSpellAbilityId() == &#039;AHtc&#039; 
endfunction

globals
    integer i = 0
endglobals

function Count takes nothing returns boolean
    return GetWidgetLife (GetFilterUnit () &gt; 0.405 )
endfunction

function Add takes nothing returns nothing
    set i = i + 1
endfunction

function kill2 takes nothing returns nothing
    call KillUnit( GetEnumUnit())
endfunction

function Trig_Remove_Archers_Actions takes nothing returns nothing
    local group g = GetUnitsOfTypeIdAll(&#039;earc&#039;)
    call ForGroupBJ(g, function Count)
    call ForGroup(g, function Add)
    call ForGroup(g, function kill2)
    call DestroyGroup(g)
    call DisplayTextToForce(GetPlayersAll(), &quot;Number of Archers Killed: &quot;+I2S(i) )
    set i = 0
endfunction
 

Flare

Stops copies me!
Reaction score
662
JASS:
 &gt; 0.405 )


Ah, mistake on my part. Should be
JASS:
) &gt; 0.405
//Bracket on the wrong side <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />

//And the end result (which should work)
return GetWidgetLife (GetFilterUnit ()) &gt; 0.405
 

N-a-z-g-u-l

New Member
Reaction score
30
you dont need to use 0.405 there... dead units have 0.000 hp :)

proof:
JASS:
    // GetTriggerUnit() is a soldier with full HP
    call SetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE,0.4)
    call BJDebugMsg(R2S(GetUnitState(GetTriggerUnit(),UNIT_STATE_LIFE)))
    // It displays 0.000.


just wanted to state this somewhere, i often see 0.405, but it makes absolutely no sense... you could use this if you need to know whether a unit dies after it takes x damage, but GetUnitState(U,UNIT_STATE_LIFE) will NEVER return a value between 0.000 and 0.405, neither it will return a negative value...
And if i am horribly wrong, correct me
 

Beetlebomb

New Member
Reaction score
43
Well what i'm trying to do here, Nazgul, is make it kill all archers on my map when I use the ability thunderclap and have it display how many archers are killed; and it works fine except for that it counts dead archers as well. So that's what Flare is helping me with at the moment. Trying to figure out why this widget stuff ain't working.


Which, btw Flare, is still counting dead units even though there's no more jasshelper errors, lol!

Wow, this is frustrating. Especially for such a simple trigger such as this. I appreciate you sticking around for this.
 

N-a-z-g-u-l

New Member
Reaction score
30
well, sorry, my post did not have to do much with the original topic...

JASS:
function KillAndCount takes nothing returns nothing
    if GetUnitState(GetEnumUnit(),UNIT_STATE_LIFE)&gt;0 then
        set bj_groupCountUnits = bj_groupCountUnits + 1
        call KillUnit(GetEnumUnit())
    endif
endfunction

function Trig_Remove_Archers_Actions takes nothing returns nothing
    local group g = GetUnitsOfTypeIdAll(&#039;earc&#039;)
    set bj_groupCountUnits = 0
    call ForGroup(g, function KillAndCount )
    call DestroyGroup(g)
    set g = null
    call DisplayTextToForce(GetPlayersAll(),I2S(bj_groupCountUnits)+&quot; Archers have been killed.&quot; )
endfunction


this one should work perfectly... i wrote it off from my head, but i dont see any mistake right now.... by the way, i replaced the variable i with bj_groupCountUnits, because the name fits, its just a variable Blizzard.j already has, because it has a function counting units in a group, too.

now, thats a way how you CAN do it, but GetUnitsOfTypeIdAll, for example, is unneeded:

JASS:
//===========================================================================
function GetUnitsOfTypeIdAllFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == bj_groupEnumTypeId
endfunction

//===========================================================================
function GetUnitsOfTypeIdAll takes integer unitid returns group
    local group   result = CreateGroup()
    local group   g      = CreateGroup()
    local integer index

    set index = 0
    loop
        set bj_groupEnumTypeId = unitid
        call GroupClear(g)
        call GroupEnumUnitsOfPlayer(g, Player(index), filterGetUnitsOfTypeIdAll)
        call GroupAddGroup(g, result)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call DestroyGroup(g)

    return result
endfunction


thats a bit much for what you really need...

so what i would do:

JASS:
function Remove_Archers_Condition takes nothing returns boolean
    // This function actually is a condition, but you can use it for your actions, too, which means, the script runs a bit faster
    local unit U = GetFilterUnit()
    if (GetUnitTypeId(U)==&#039;earc&#039;) and (GetUnitState(U,UNIT_STATE_LIFE)&gt;0) then
        set bj_groupCountUnits = bj_groupCountUnits + 1
        call KillUnit(U)
    endif
    set U = null
    return false // No unit will be saved into the group, so it is faster
endfunction

function Trig_Remove_Archers_Actions takes nothing returns nothing
    local group g = CreateGroup()
    set bj_groupCountUnits = 0
    call GroupEnumUnitsInRect(g, GetWorldBounds(), Condition( function Remove_Archers_Condition ) )
    call DestroyGroup(g)
    set g = null

    // This function can only be used with GetLocalPlayer() as the first argument, and shows the message to all players executing it, in this case all human players
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, I2S(bj_groupCountUnits)+&quot; Archers have been killed.&quot;)
endfunction


i hope my script does not contain any mistakes, did not test it right now

however, it could be that the second code is a bit hard to understand, then its better to just stick to the first one i think

and Flare: He used the condition as a function in ForGroup, its quite clear that it did not filter any units out
 

Beetlebomb

New Member
Reaction score
43
I'm trying to use your last jass code and there seems to be one error(i believe).

My jasshelper says that "call GroupEnumUnitsInRect(g , GetWorldBounds() , Condition(Remove_Archers_Condition))" undeclared variable Remove_Archers_Condition

I just added in: "Condition(function Remove_Archers_Condition))" and it worked, but now it doesn't kill the archers, and it doesn't display ANYTHING. :(

edit: switched to your first jass one and it works great. I'd like to learn how to make this jass script more efficient though if you're willing to explain a little. :)


EDIT: scratch that, it triggers whenever ANY spell is cast. Not only thunderclap.
 

Flare

Stops copies me!
Reaction score
662
> "call GroupEnumUnitsInRect(g , GetWorldBounds() , Condition(Remove_Archers_Condition))" undeclared variable Remove_Archers_Condition

you must use function i.e.
JASS:
call GroupEnumUnitsInRect(g , GetWorldBounds() , Condition(function Remove_Archers_Condition))
//Notice that function was added before Remove_Archers_Condition


Unless you identify it as a function by adding 'function' before it, WE will assume it to be a variable (if you assigned a code variable to that particular function, there wouldn't be a problem leaving out the function and using your variable's name)

(IMO), one of the more annoying things about JASS but there's not much that can be done about it
 

N-a-z-g-u-l

New Member
Reaction score
30
I'm trying to use your last jass code and there seems to be one error(i believe).

My jasshelper says that "call GroupEnumUnitsInRect(g , GetWorldBounds() , Condition(Remove_Archers_Condition))" undeclared variable Remove_Archers_Condition

I just added in: "Condition(function Remove_Archers_Condition))" and it worked, but now it doesn't kill the archers, and it doesn't display ANYTHING. :(

edit: switched to your first jass one and it works great. I'd like to learn how to make this jass script more efficient though if you're willing to explain a little. :)

i think i will do this later, but for now i am visiting a friend of mine ;)
 

Beetlebomb

New Member
Reaction score
43
I tried adding in:

JASS:
function Cond takes nothing and returns boolean
    if( GetSpellAbilityId(), == &#039;AHtc&#039; ) then
    return true
    endif
    return false
endfunction


but i get the feeling i'm doing something wrong. jasshelper tells me "Expect 'returns'" but I have it returning a boolean so...


EDIT: Nevermind! I got it, finally this topic is over. Thanks everybody so much. I know enduring with a Jass nublet is frustrating. Once I get some knowledge into my noggin' i'll be sure to contribute to this Jass help sub-forum ^^
 

Flare

Stops copies me!
Reaction score
662
Oh... that can be improved :D
JASS:
return GetSpellAbilityId () == &#039;AHtc&#039;


If you want to continue doing it your way...
JASS:
function Cond takes nothing and returns boolean
    if( GetSpellAbilityId(), == &#039;AHtc&#039; ) then
    return true
    else
    return false
    endif
endfunction
//You were returning a true within the if, then a guaranteed return false <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
//And where did that comma after GetSpellAbilityId () come from?
 

Beetlebomb

New Member
Reaction score
43
haha, yea; it did that before (If I remember correctly it looked just like yours) but I got some error so I just went along with the longer way, but I just C&P'sed urs and it worked so, pfffft.


Thx again.




edit: I also put 'and' after takes nothing... I really DONT remember putting that. haha

edit: I thought the comma looked pretty.
 

Flare

Stops copies me!
Reaction score
662
I never remember using a comma in GetSpellAbilityId check...

Anyway, commas are only used (as far as I know) for separating arguments in a function i.e.

JASS:
function MyFunc1 takes integer i, real r returns real
return r + I2R (i)
endfunction

function MyFunc2 takes nothing returns nothing
local integer integervar = 1
local real realvar = MyFunc1 (integervar, realvar)
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top