Which unit?

tommerbob

Minecraft. :D
Reaction score
110
I've got a spell that when a unit comes within 50 of a trap, the unit is ensnared, and the trap is removed from the game. Code:

JASS:

private struct Trap extends array
    //! runtextmacro AIDS()
    private trigger t
    private triggeraction ta
	
    private static method Act takes nothing returns nothing
        local thistype d = thistype[GetTriggerUnit()]
        call UnitAddAbility(DUMMY, TRAP_ID)   //Add dummy buff
        call IssueTargetOrder(DUMMY, "ensnare", d.unit)
        call UnitRemoveAbility(DUMMY, TRAP_ID)
        call RemoveUnit(????)   //                       <---------- How do I reference the trap unit to remove it?
    endmethod
    
    private static method AIDS_filter takes unit u returns boolean
        return GetUnitTypeId(u) == TRAP 
    endmethod
    
    private method AIDS_onCreate takes nothing returns nothing
        set this.t = CreateTrigger()
        set this.ta = TriggerAddAction(this.t,function thistype.Act)
        call TriggerRegisterUnitInRange(this.t, this.unit, 50., null)
    endmethod
    
    private method AIDS_onDestroy takes nothing returns nothing
        call TriggerRemoveAction(this.t, this.ta)
        call DestroyTrigger(this.t)
        set this.ta = null
        set this.t = null
    endmethod
endstruct


In the Act method, the trap is supposed to be removed. The problem is, how do I reference the trap?
 

Laiev

Hey Listen!!
Reaction score
188
Use a variable member to define it.

Also AIDS should be used bellow everything.
 

Dirac

22710180
Reaction score
147
No wait i'm a bit confused.
first your struct indexes only TRAP type units.
When they're indexed a trigger is created for each one of them that detects whenever a unit comes unto range
When this trigger fires is when the mess begins
[ljass]local thistype d = thistype[GetTriggerUnit()][/ljass] I suppose that here you're reffering to the TRAP, to avoid a trigger evaluation just use [ljass]local thistype d = GetUnitUserData(GetTriggerUnit())[/ljass]
Then you're adding an ability to a global dummy and make it cast it upon the TRAP? why?
There's a native called GetEnterUnit or GetEnteringUnit.
Also you should know that the event "unit enters range" is a periodic check (every 0.1 seconds) for every unit nearby it, you could do it manually.
And yes, the AIDS textmacro should be run at the end.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Hm, the best thing that comes to my mind is to attach the whole Trap struct to the trigger:

JASS:
private struct Trap extends array
    //! runtextmacro AIDS()
    private trigger t
    private triggeraction ta
	
    private static method Act takes nothing returns nothing
        local Trap t = LoadInteger(<some hashtable>, H2I(GetTriggeringTrigger()), 0xDirac) // get the attached Trap struct from the trigger
        call UnitAddAbility(DUMMY, TRAP_ID)
        call IssueTargetOrder(DUMMY, "ensnare", d.unit)
        call UnitRemoveAbility(DUMMY, TRAP_ID)
        call RemoveUnit(t.unit) // t.unit shold work =)
    endmethod
    
    private static method AIDS_filter takes unit u returns boolean
        return GetUnitTypeId(u) == TRAP 
    endmethod
    
    private method AIDS_onCreate takes nothing returns nothing
        set this.t = CreateTrigger()
        set this.ta = TriggerAddAction(this.t,function thistype.Act)
        call TriggerRegisterUnitInRange(this.t, this.unit, 50., null)
        call SaveInteger(<some hashtable>, H2I(this.t), 0xDirac /* joke poke =)*/,  this) // attach the Trap struct to the trigger
    endmethod
    
    private method AIDS_onDestroy takes nothing returns nothing
        call TriggerRemoveAction(this.t, this.ta)
        call DestroyTrigger(this.t)
        set this.ta = null
        set this.t = null
    endmethod
endstruct


@Dirac
The GetEnterUnit or GetEnteringUnit is a reference to the unit that enters in range of the trap, not the trap itself, and it's equvalent to the GetTriggerUnit() native.
 

tommerbob

Minecraft. :D
Reaction score
110
No wait i'm a bit confused.
first your struct indexes only TRAP type units.
When they're indexed a trigger is created for each one of them that detects whenever a unit comes unto range
When this trigger fires is when the mess begins
[ljass]local thistype d = thistype[GetTriggerUnit()][/ljass] I suppose that here you're reffering to the TRAP, to avoid a trigger evaluation just use [ljass]local thistype d = GetUnitUserData(GetTriggerUnit())[/ljass]
Then you're adding an ability to a global dummy and make it cast it upon the TRAP? why?
There's a native called GetEnterUnit or GetEnteringUnit.
Also you should know that the event "unit enters range" is a periodic check (every 0.1 seconds) for every unit nearby it, you could do it manually.
And yes, the AIDS textmacro should be run at the end.

GetTriggerUnit() and GetEnteringUnit() return the same thing, which is not what I need.

JASS:


This references the entering unit, not the trap. I need it to reference the trap so that I can remove it. How do I do that?

@Sgqvur: Is using a hashtable the only way? I really don't want to use one if I can avoid it. I just don't like them.

Also, why do I need to run Aids textmacro at the end? I've always done it at the beginning, and everything works fine.
 

Dirac

22710180
Reaction score
147
There is a very obvious reason you have to run it at the end: Trigger evaluations.
Remember that JASS can't read functions below other functions, only above.
The textmacro calls the AIDS_Whatever function everytime an indexing event is fired, but these functions would be below them if the textmacro is at the top.
And yes, it seems that the only way to reffer to that unit is by hashtable use, to store the trigger's handle.
Again, use the GetUnitUserData instead of the operator.
 

tommerbob

Minecraft. :D
Reaction score
110
There is a very obvious reason you have to run it at the end: Trigger evaluations.

Its not obvious to everyone. I don't even know what a trigger evaluation is.

Remember that JASS can't read functions below other functions, only above.
The textmacro calls the AIDS_Whatever function everytime an indexing event is fired, but these functions would be below them if the textmacro is at the top.

I realize this is true, but then why don't I get errors from all of my Aids structs? Cause I always do the textmacro's at the top.
 

Dirac

22710180
Reaction score
147
Because vJass compensates with trigger evaluations (which are way slower) and code repetition (which sucks) to be able to call the function. This behavior happens only inside structs.

A trigger evaluation in a nutshell...
JASS:
local trigger trig = CreateTrigger()
call TriggerAddCondition(trig,Filter(function SomeFunc))
call TriggerEvaluate(trig)

The function SomeFunc is called, but through a trigger evaluation, instead of just
JASS:
call SomeFunc()
 

tommerbob

Minecraft. :D
Reaction score
110
Hmm, okay. I think that makes sense.

I created a hashtable, but I'm getting all sorts of syntax errors. What is the H2I function? It doesn't work.

JASS:
private struct Trap extends array
    private trigger t
    private triggeraction ta
	
    private static method Act takes nothing returns nothing
        local Trap t = LoadInteger(H, H2I(GetTriggeringTrigger()), 0) // get the attached Trap struct from the trigger
        call UnitAddAbility(DUMMY, TRAP_ID)
        call IssueTargetOrder(DUMMY, "ensnare", GetTriggerUnit())
        call UnitRemoveAbility(DUMMY, TRAP_ID)
        call RemoveUnit(t.unit)
        call FlushChildHashtable(H, H2I(t.t))
    endmethod
    
    private static method AIDS_filter takes unit u returns boolean
        return GetUnitTypeId(u) == TRAP 
    endmethod
    
    private method AIDS_onCreate takes nothing returns nothing
        set this.t = CreateTrigger()
        set this.ta = TriggerAddAction(this.t,function thistype.Act)
        call TriggerRegisterUnitInRange(this.t, this.unit, 50., null)
        call SaveInteger(H, H2I(this.t), 0, this) // attach the Trap struct to the trigger
    endmethod
    
    private method AIDS_onDestroy takes nothing returns nothing
        call TriggerRemoveAction(this.t, this.ta)
        call DestroyTrigger(this.t)
        set this.ta = null
        set this.t = null
    endmethod
    //! runtextmacro AIDS()
endstruct
 

luorax

Invasion in Duskwood
Reaction score
67
H2I = [ljass]GetHandleId[/ljass]. There was a bug before 1.24; by returning 0 at the end of any function, you were able to convert things to different types. Just like this:

JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function I2H takes integer i returns handle 
    return i
    return 0
endfunction


And this worked for everything. You could convert a destructable to a trackable, using its pointer. But it won't work anymore, it was fixed in 1.24
 

tommerbob

Minecraft. :D
Reaction score
110
Okay it works. :)

Am I flushing the hashtable correctly? I never use them, so I don't know what I'm doing. :p
 

luorax

Invasion in Duskwood
Reaction score
67
You should use a Table instead IMO.

There were a higher version on THW but I couldn't find it. Maybe it got deleted after Vexorian decided to update the old one? IDK, Bribe's one looked better.
 

luorax

Invasion in Duskwood
Reaction score
67
Well, then THW's search function is bugged; I searched for "Table" and set "Bribe" as user name and didn't show me that topic. W/E, that's the latest version, use that then.

Extremely useful +1
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      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