Explanation on this issue?

Reaction score
91
I have a script that is supposed to issue usage of a specific item at some point of the game. Because there are a lot of items that I use based on instant, unit or point cast, I used a simplified method and just call the 3 natives instead of checking whether the item should be casted on units/points/instantaneously or not.

JASS:

// This code is executed in a loop so I use an O(n) search in an array for item types. "crap" is an item variable, don't get confused... ^^
// ITEM[a] is my integer array containing all item types.
                        set crap = GetItemOfTypeFromUnitBJ(this.cast, ITEM[a])
                        if not UnitUseItemPoint(this.cast, crap, this.tx, this.ty) then
                            if not UnitUseItem(this.cast, crap) then
                            // should work?
                                if not UnitUseItemTarget(this.cast, crap, this.targ) then
                                    call BJDebugMsg("FAIL ?!?!?!?")
                                endif
                            endif
                        endif

Say this is a part of my script that issues that item casting. Everything works perfectly except for unit targeting... This event is supposed to trigger when a spell is cast and if the specific item targets units, it should target a unit. The problem is that the item was never used on the target even though I had no other mistakes in my code. After some toying around I rearranged the order of casting and found out that this time it works flawlessly.

JASS:

// This code is executed in a loop so I use an O(n) search in an array for item types. "crap" is an item variable, don't get confused... ^^
                        set crap = GetItemOfTypeFromUnitBJ(this.cast, ITEM[a])
                        if not UnitUseItemPoint(this.cast, crap, this.tx, this.ty) then
                            if not UnitUseItemTarget(this.cast, crap, this.targ) then
                                if not UnitUseItem(this.cast, crap) then
                                    call BJDebugMsg("FAIL ?!?!?!?")
                                endif
                            endif
                        endif


So, can anybody explain to me why the first method does not work for unit targeting while the second works for everything?
Even though in the first method FAIL is never displayed, it does not cast the item!
 

Tom Jones

N/A
Reaction score
437
The obvious question is then how far the execution goes in the first code? Does UnitUseItem(...) return a strange boolean, just as IsUnitType(...)? Try comparing to false instead of using not, and try adding a debug message inside each if statement to see how far the code goes.
 
Reaction score
91
In both situations FAIL never gets displayed (when it's a unit-target item) so it is returning TRUE... but there is no issued item casting.

JASS:
//
                        set crap = GetItemOfTypeFromUnitBJ(this.cast, ITEM[a])
                        //if not UnitUseItemPoint(this.cast, crap, this.tx, this.ty) then
                            //if not UnitUseItemTarget(this.cast, crap, this.targ) then
                                //if not UnitUseItem(this.cast, crap) then
                        if UnitUseItemPoint(this.cast, crap, this.tx, this.ty) == false then
                            if UnitUseItem(this.cast, crap) == false then
                                if UnitUseItemTarget(this.cast, crap, this.targ) == false then
                                    call BJDebugMsg("FAIL ?!?!?!?")
                                endif
                            endif
                        endif


Totally same situation as with the not example... :nuts: Swapping UnitUseItem and UnitUseItemTarget works just fine.
 

Rainther

I guess I should write something of value here...
Reaction score
61
Confirm with debug messages which of the "if"s that makes it not reach "FAIL" and mentioned above. If you already have done it, you at least haven't said it.
 
Reaction score
91
JASS:

if UnitUseItem(this.cast, crap) == false then


After this part, UnitUseItemTarget does not get executed since UnitUseItem returns true and stops further actions... This is quite odd since UnitUseItem does not require any target and should return false, however even though it gives the unexpected result, it does not cast the item.
I also noticed something odd with those natives for point targeting items (only point since I use Channel with that option):

JASS:

                        set crap = GetItemOfTypeFromUnitBJ(this.cast, ITEM[a])
                        if not UnitUseItemPoint(this.cast, crap, this.tx, this.ty) then
                            if not UnitUseItem(this.cast, crap) then
                            // should work?
                                if not UnitUseItemTarget(this.cast, crap, this.targ) then
                                    call BJDebugMsg("FAIL ?!?!?!?")
                                endif
                            endif
                        endif

FAIL gets displayed, although it shouldn't since UnitUseItemPoint is supposed to return true, right?
 

Tom Jones

N/A
Reaction score
437
I think it has something to do with range. If the target is out of range of the unit with the item it'll return false. This would make perfect sense because:

UnitUseItemPoint(...) - Has range.
UnitUseItemTarget(...) - Has range.
UnitUseItem(...) - Target is the unit itself, so no range.

I have an idea that UniUseItem(...) always will return true. I'll do some testing to see whether or not this is true.

*Edit*

Here's how I tested:
JASS:
scope ItemTest initializer Init

globals
    private constant integer WHICH_ID   = 1     //Range 0-3.
    private constant real ITEM_RANGE    = 500
    private constant integer TARGET_ID  = 'hfoo'
    
    private unit U   
    private string array S
    private integer array ITEM_IDS  
    private unit array TARGET_UNITS
    private real array TARGET_POINTS
endglobals

private function onTest takes nothing returns nothing
    local item theitem = UnitAddItemById(U,ITEM_IDS[WHICH_ID])
    local integer i = 0
    local string s
    local boolean array b 
        
    loop
        exitwhen i == 2
        set b[i*3] = UnitUseItemPoint(U,theitem,TARGET_POINTS[i*2],TARGET_POINTS[i*2+1])
        set b[i*3+1] = UnitUseItemTarget(U,theitem,TARGET_UNITS<i>)
        set b[i*3+2] = UnitUseItem(U,theitem)
        set i = i+1
    endloop
    set i = 0
    loop
        exitwhen i == 6
        if i &lt; 3 then
            set s = &quot; within range = &quot;
        else
            set s = &quot; outside range = &quot;
        endif
        if b<i> then
            call BJDebugMsg(&quot;|cff00ff00&quot;+S[i-(i/3)*3]+s+&quot;true&quot;)
        else
            call BJDebugMsg(&quot;|cffff0000&quot;+S[i-(i/3)*3]+s+&quot;false&quot;)
        endif
        set i = i+1
    endloop
endfunction

private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer i = 0
    local real r = ITEM_RANGE
    
    call TriggerRegisterTimerEvent(trig,1,false)
    call TriggerAddAction(trig,function onTest)
    
    set U = CreateUnit(Player(0),&#039;Hamg&#039;,0,0,0)
    call SetUnitInvulnerable(U,true)
    call UnitRemoveAbility(U,&#039;Aatk&#039;)
    
    loop
        exitwhen r &gt; 2*ITEM_RANGE
        set TARGET_UNITS<i> = CreateUnit(Player(1),TARGET_ID,r,0,0)
        set TARGET_POINTS[i*2] = (r/2)*(i+1)
        set TARGET_POINTS[i*2+1] = 0
        set r = r+ITEM_RANGE
        set i = i+1
    endloop
    
    set ITEM_IDS[0] = &#039;ssil&#039; //Point target item with cooldown.
    set ITEM_IDS[1] = &#039;wswd&#039; //Point target item without cooldown.
    set ITEM_IDS[2] = &#039;wlsd&#039; //Unit target item with cooldown.
    set ITEM_IDS[3] = &#039;wshs&#039; //Unit target item without cooldown.
    
    set S[0] = &quot;Point target&quot;
    set S[1] = &quot;Unit target&quot;
    set S[2] = &quot;No targer&quot;
    call FogModifierStart(CreateFogModifierRect(Player(0),FOG_OF_WAR_VISIBLE,GetWorldBounds(),true,false))
endfunction
endscope</i></i></i>


As I expected, UnitUseItem(...) will always return true, unless ofcourse the item is on cooldown.
UnitUseItemPoint(...) always returned false, even when using point targeted base items. I expect that this has something to do with a flaw in my test.
UnitUseItemTarget(...) works fine.
Range has to impact on the functions.
 
Reaction score
91
> I expect that this has something to do with a flaw in my test.
In both my cases (the non-working and the working one) it returns false... Maybe a flaw in the native? o_O
Good job for the tests, I will try to remember these things.
 
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

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top