A simple pain; Tower Abilities

Tyman2007

Ya Rly >.
Reaction score
74
It seems as though I've ran into a problem here.

I've made a simple trigger enhanced spell to debug a function that I have created to show the range of each tower.

It seems as though that when a tower casts an ability, the trigger is not firing.
The trigger works when i put the ability on a non-structure unit.

Is there any event that I can use for tower abilities?
Would GTrigger work for such a thing?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
There's no reason I can think of that a spell's trigger would work on a non-structure unit when it doesn't work on a tower. Could you show your trigger and function?
 

Tyman2007

Ya Rly >.
Reaction score
74
My simple snippet;
JASS:
library GetRange

    //! textmacro AddTowerRange takes TOWERTYPE, RANGE
    elseif (i == $TOWERTYPE$) then
    return $RANGE$
    //! endtextmacro

    function GetRange takes integer i returns real
        if (i == 'hgtw') then
            return 700
        //! runtextmacro AddTowerRange("'hctw'", "800")
        endif
        return 0.00
    endfunction

endlibrary


My test trigger;
JASS:
scope Range initializer Init

    globals
        private constant integer ABIL_CODE = 'A002'
    endglobals

    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == ABIL_CODE
    endfunction

    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = GetUnitTypeId(u)
        local real r = GetRange(i)
    
        if r != 0 then
            call BJDebugMsg("r is not equal to 0")
        else
            call BJDebugMsg("r is equal to 0 and has not been set")
        endif
        
        if i != 0 then
            call BJDebugMsg("i is registered")
        else
            call BJDebugMsg("i has not been registered")
        endif
        
        if u != null then
            call BJDebugMsg("u is registered")
        else
            call BJDebugMsg("u has not been registered")
        endif
    endfunction

    private function Init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( trig, Condition( function Conditions ) )
        call TriggerAddAction( trig, function Actions )
    endfunction

endscope


I don't think anything's wrong on the triggering end.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Hm. Well, are you sure you gave the same ability to the towers as to the unit for which it worked? :D

I don't see anything obviously wrong, so just double-check all the values, and then: when everything looks correct, something else might be interfering. Do you have any other triggers dealing with spell events?
 

Tyman2007

Ya Rly >.
Reaction score
74
Sorry for the delayed reply, nope.

I didn't post the triggers because it doesn't seem like a trigger issue here.

I made sure that it was the same ability.

I have another trigger dealing with spell effects, but it's dealing with a different spell.

It only works on non-structure units, which is a bit strange.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Wait, can you use hashtable instead of if elseif endif.
O(1) is faster than O(n).
 

Tyman2007

Ya Rly >.
Reaction score
74
I've been hearing you say that a lot and I still don't understand what that means :p (O(1) is faster than O(n))

I really despise the use of hashtables, but if it's more efficient, then I will have to try it.

Please explain?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
I've been hearing you say that a lot and I still don't understand what that means :p (O(1) is faster than O(n))
Big O notation is a way to refer to computational efficiency.

O(n) means that the time it will take for some code to process a task depends on the task in a linear fashion - if you give it a data set with "n" number of elements, it will take twice as long as if you give it data with half as many elements. Your chain of [lJASS]elseif[/lJASS]s will take longer to find the correct result if you give it a tower rawcode at the end of the chain than if you give it a rawcode that's at the beginning; on average, if you give it rawcodes with an even probability between all the possible rawcodes, it will average O(n/2) = O(n) complexity, with n being the number of elseifs.

I say O(n/2) = O(n) because it's a measure of complexity, not a measure of actual speed. Multipliers don't matter, because you're looking for the trend of computational time, not the specifics. Common measures will be O(n), O(n^2) (which, as you can imagine, rapidly slows down with larger data sets), and O(n log n) which is often the complexity achieved by optimized sort algorithms.

O(1) means that no matter what task you give some code, it will take the same amount of time. Note that this does not necessarily mean it's faster, if your comparison is with an O(n) algorithm with which you would only use simple data sets.

Hashtables are O(1) because instead of going "is it this value? no? try the next one", you simply feed it a value and it retrieves the saved data in the same amount of time no matter what.

P.S. Your tower/non-tower problem is still baffling. :eek:
 

Tyman2007

Ya Rly >.
Reaction score
74
Oh I get it now! Thank you!

The problem is, is that I suck at hashtables. Took me 5 minutes to learn them and master them with GUI, but doing what you're saying I should do is the problem I am facing.

The trigger I made was more for me practicing the use of text macros.
Would just taking out the elseifs and replacing them with normal if/then's be something like what you're saying?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
No, it is like something like this...
JASS:
//Classical example for attaching data to rawcodes.
library GetRange initializer Init

    globals
        private hashtable hasht = InitHashtable()
    endglobals

    //! textmacro AddTowerRange takes TOWERTYPE, RANGE
    call SaveReal(hasht,$TOWERTYPE$,0,RANGE)
    //! endtextmacro

    function GetRange takes integer i returns real
        return LoadReal(hasht,$TOWERTYPE$,0)
    endfunction
    
    private function Init takes nothing returns nothing
        //! runtextmacro AddTowerRange("'hctw'", "800.")
    endfunction
endlibrary
 

Tyman2007

Ya Rly >.
Reaction score
74
Hate hashtables..

But thanks!

Seems a lot easier than the way I was going at it, lol

Just had to take that trigger and fix the couple of errors.

But now.. the main problem is still bugging me.. Towers can't use triggered abilities T.T
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top