Boolean does not listen?

wraithseeker

Tired.
Reaction score
122
JASS:
scope Necromancy initializer Init

globals
    private constant integer SPELL = 'A00J'
    private constant integer HEROID = 'U000'
    private integer Count = 0
    private timer TIMER = CreateTimer()
    private constant real TIMEOUT = 1
    private group Casters = CreateGroup()
    private boolexpr b
    private boolexpr unitcheck
endglobals

private struct data
    implement AutoData
    static data temp
    unit target
    boolean used
    timer t
    
    
method onDestroy takes nothing returns nothing
    
endmethod
endstruct

private function CheckUnits takes nothing returns boolean
    local data d
    set d = d.temp
    return GetOwningPlayer(GetFilterUnit()) == GetOwningPlayer(d.target) and not IsUnitType(GetFilterUnit(),UNIT_TYPE_HERO)
endfunction

private function Check takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == HEROID
endfunction

private function Conditions takes nothing returns boolean
    return GetLearnedSkill() == SPELL
endfunction

private function Remove takes nothing returns nothing
    local data d = GetTimerData(GetExpiredTimer())
    set Damage[d.target] = Damage[d.target] - 5
    set MaxMana[d.target] = MaxMana[d.target] - 50
    call ReleaseTimer(d.t)
    call BJDebugMsg("released")
    set d.used = false
endfunction

private function DoEffect takes nothing returns nothing
    local unit u = GetEnumUnit()
    local unit t
    local data d = data<u>
    local data c
    set d.temp = d
    call GroupEnumUnitsInRange(ENUM_GROUP,GetUnitX(u),GetUnitY(u),600,unitcheck)
    loop
        set t = FirstOfGroup(ENUM_GROUP)
        exitwhen t == null
        set c = data[t]
        if c == 0 then
            set c = data.create()
            set c.used = false
            set c.target = t
            set c.t = NewTimer()
            set data[t] = d
        endif
        if not c.used then
            set c.used = true
            set Damage<u> = Damage<u> + 5
            set MaxMana<u> = MaxMana<u> + 50
            call BJDebugMsg(&quot;adding&quot;)
            call SetTimerData(c.t,d)
            call TimerStart(c.t,5,false,function Remove)
        endif
        call GroupRemoveUnit(ENUM_GROUP,t)
    endloop
    set u = null
endfunction

private function Loop takes nothing returns nothing
    call ForGroup(Casters,function DoEffect)
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local data d
    if not IsUnitInGroup(u,Casters) then
        set d = data.create()
        set d.target = u
        set data<u> = d
    endif
    if FirstOfGroup(Casters) == null then
        call TimerStart(TIMER,TIMEOUT,true,function Loop)
    endif
    call GroupAddUnit(Casters,d.target)
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(t,Condition(function Conditions))
    call TriggerAddAction(t,function Actions )
    set b = Filter(function Check)
    set unitcheck = Filter(function CheckUnits)
endfunction
endscope</u></u></u></u></u></u>


JASS:
  if not c.used then
            set c.used = true
            set Damage<u> = Damage<u> + 5
            set MaxMana<u> = MaxMana<u> + 50
            call BJDebugMsg(&quot;adding&quot;)
            call SetTimerData(c.t,d)
            call TimerStart(c.t,5,false,function Remove)
        endif</u></u></u></u>


This part is running 2 times although it's supposed to run once.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I'd personally use "if c.used == false" rather than the not syntax.

Put this on the outside of your loop and take out the if.
JASS:
        if c == 0 then
            set c = data.create()
            set c.used = false
            set c.target = t
            set c.t = NewTimer()
            set data[t] = d
        endif
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Add an extra unit variable into the struct.

Set c.unitvariablename = FirstOfGroup(ENUM_GROUP)

Creating a new struct for each unit is kind of overkill. What does:

JASS:
implement AutoData
do?
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Would you mind saying what your spell is supposed to do? It's kind of hard to figure it out with the unfamiliar syntax.

What I see it doing is it takes a whole group, and for each unit in that group it creates another group of every unit within range and then does some action. That boolean running the second time could in fact be there because one unit is used more than once, i.e. it is within range of two units so it goes through that loop twice.

JASS:
private function Loop takes nothing returns nothing
    call ForGroup(Casters,function DoEffect)
endfunction


That does your loop for EVERY unit in the group individually.
 

wraithseeker

Tired.
Reaction score
122
This is how the spell goes

Every 1 second, pick a unit type of my hero and checks 600 range whether there is a animated dead beside him and then if there is add damage and mana, it is supposed to be added once and not twice or more.

Casers are the hero who learned the spell.

EDIT: it is within range of two units so it goes through that loop twice.

Not possible as I tested with only one hero.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Then you do need to move that block of code out of the loop. For every unit it finds in that group it'll create another struct and go thru the actions even though you only want them done once. Creating a struct for each unit in range is still overkill for this spell, and because it is periodic it might cause your map to lag.

Instead of moving that creation block outside you could add an exitwhen in there like such:

JASS:
        if not c.used then
            set c.used = true
            set Damage<u> = Damage<u> + 5
            set MaxMana<u> = MaxMana<u> + 50
            call BJDebugMsg(&quot;adding&quot;)
            call SetTimerData(c.t,d)
            call TimerStart(c.t,5,false,function Remove)
            exitwhen true //&lt;-----------
        endif</u></u></u></u>
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
JASS:
if not c.used then
            set c.used = true
            set Damage<u> = Damage<u> + 5
            set MaxMana<u> = MaxMana<u> + 50
            call BJDebugMsg(&quot;adding&quot;)
            call SetTimerData(c.t,d)
            call TimerStart(c.t,5,false,function Remove)
            exitwhen true //&lt;-----------
        endif

</u></u></u></u>

Would that even work? Because...
JASS:
if not c.used then // If c.used is false...
exitwhen true // then exit if false is true?
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
JASS:
if not c.used then
            set c.used = true
            set Damage<u> = Damage<u> + 5
            set MaxMana<u> = MaxMana<u> + 50
            call BJDebugMsg(&quot;adding&quot;)
            call SetTimerData(c.t,d)
            call TimerStart(c.t,5,false,function Remove)
            exitwhen true //&lt;-----------
        endif

</u></u></u></u>

Would that even work? Because...
JASS:
if not c.used then // If c.used is false...
exitwhen true // then exit if false is true?


c.used is false on initialization, see the if block above it. The code is really weird :X. Doesn't exitwhen true always exit the loop? or is the correct syntax exitwhen true == true. you got your noodles back! :D
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
The syntax is fine, I mixed up this with exitwhen false, which would not work. This however, worked.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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