Boolean does not listen?

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
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
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
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.
 
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
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
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
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
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.
  • C Cherry.Grove:
    So what's the whole reforged situation? Do we have to run the classic version bootleg now?
  • C Cherry.Grove:
    My boyfriend is super into Bethesda modding so I'm probably going to join him in that for a bit, then move on to making mobile/browser games.
  • C Cherry.Grove:
    I mostly just want to look at my old projects because I know I posted uploads on here somewhere.
  • C Cherry.Grove:
    My one game was basically Among Us but you sabotaged an entire medieval city simulated drastically inefficiently with dynamic NPCs :S
  • C Cherry.Grove:
    of course I never finished it x D
  • jonas jonas:
    xD
  • jonas jonas:
    I think you can still run the original game, just there's a chance your map won't work with the newer patches
  • jonas jonas:
    what development framework have you been looking at for mobile development?
  • jonas jonas:
    I'm currently creating (as a hobby) a space invaders like game for mobile using Xamarin, after starting a few larger projects that I also may not have finished :rolleyes::p
  • The Helper The Helper:
    Awesome! you should look at the Atari VCS platform it does not have a huge user base but the one it has is super active at around 11k and they have no games in there store
  • The Helper The Helper:
    basically it is linux
  • The Helper The Helper:
    OMG it is BanLord as Blackveiled on the forum
  • The Helper The Helper:
    what is up buddy
  • jonas jonas:
    thanks for the tip, that sounds cool. Never heard about the VCS before but seems like it should be a good match
  • tom_mai78101 tom_mai78101:
    The winter vacation left a toll on me. I missed staying up late and sleeping in late.
  • C Cherry.Grove:
    i haven't looked into it yet
  • C Cherry.Grove:
    If I could use something Python compatible it would save me some learning
  • C Cherry.Grove:
    But Unity might be easiest
  • C Cherry.Grove:
    looking at old posts here makes me happy. Makes me be all like "wow I was pretty smart in 2009"
  • C Cherry.Grove:
    mostly failing at life through adulthood really demotivated me for a while
  • C Cherry.Grove:
    ....what I don't get is why the fuck they would force us to permanently convert to a version of the game everyone fucking hated : \
  • C Cherry.Grove:
    Raid Shadow Legends texture pack smh
  • jonas jonas:
    Most people fail at life throughout their adulthood. Sometimes we get to learn from it. Usually it just feels like crap.
  • The Helper The Helper:
    What does not kill you makes you stronger is what they say

    Members online

    No members online now.

    Affiliates

    Hive Workshop NUON Dome
    Top