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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      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