Creating Triggers in Structs

TheOverWhelm

Member
Reaction score
16
Just a quickie about Structs,
From what I've noticed, you can't do a TriggerAddAction with the added function being a nonstatic method?
 

luorax

Invasion in Duskwood
Reaction score
67
Yes, TriggerAddCondition/TriggerAddAction takes a static method. However you can always declare the instance you may wanna use in the current static method (local thistype this=XYZ)
 

Romek

Super Moderator
Reaction score
964
Code variables passed to TriggerAddAction need to take no parameters. Instance (non-static) methods compile to take an integer: the struct instance, 'this'.
 

TheOverWhelm

Member
Reaction score
16
So, are static methods in one instance? Or every one?
I'm just trying to make a very -simple- DPI thing without using any external systems.
 

dudeim

New Member
Reaction score
22
static methods are the same for every struct instance unlike normal methods which can change values and do stuff for their own instance.
 

TheOverWhelm

Member
Reaction score
16
So is it possible to create a trigger for each instance with a timer event, add actions to it that'll detect which instance created it?
 

luorax

Invasion in Duskwood
Reaction score
67
No, it's impossible. You can create triggers for each instance, but the Action must be static.
If you want to store those instances (and attach them to something) you better use Table or AIDS. You can find both of them in JASS resource section.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Since there's no way for the game to inherently know which instance to call the method with, the method must be static. If you want to create an individual trigger for each instance of the spell, you could use Hashtables to attach the individual instance to the respective trigger. I made a few functions that will simplify this:

JASS:
    globals        
        private key TRIGGERS
        private key DYMET
    endglobals
    
    function interface dymet takes integer this returns nothing
    
    private function TriggerAddMethodActionCB takes nothing returns nothing
        //Runs the given non-static method with the data attached to the trigger.
        call dymet(LoadInteger(hash,DYMET,GetHandleId(GetTriggeringTrigger()))).evaluate(LoadInteger(hash,TRIGGERS,GetHandleId(GetTriggeringTrigger())))
    endfunction
    
    function TriggerAddMethodAction takes integer data, trigger t, dymet which returns nothing
        /*
        
        Attaches data to a trigger, and when the trigger is executed, it runs the method with the data.
        Attachment to triggers (instead of events, which is probably impossible) limits attachment to one data set per trigger.
        
        Example Usage (pseudo code):
            trigger t
            Data data
            
            struct Data
                method onTriggerExecute takes nothing returns nothing
                    //Do stuff with 'this'
                endmethod
            endstruct
            
            call TriggerAddMethodAction(data,t,Data.onTriggerExecute)
        
        */
        
        call SaveInteger(hash,TRIGGERS,GetHandleId(t),data)
        call SaveInteger(hash,DYMET,GetHandleId(t),which)
        call TriggerAddAction(t,function TriggerAddMethodActionCB)
    endfunction


If you cut out the comments, you can see that it does the relatively simple action of attaching the individual this 'data' and method to the individual trigger, and then when the trigger runs, it merely executes the method that is attached, and passes the data that is also attached. It's a bit of a hack, but it makes for a nice interface. :)

Random note about the code: 'dymet' stands for dynamic method (attachment).
 

TheOverWhelm

Member
Reaction score
16
I've read about everything you did in thar function and I may try it.
My question is about doing a if GetExpiredTimer()==DPICounter(i).t
I'm guessing this'd be inefficient? And what about that whole linked thread stuff? Would that do anything? Whats the actual purpose of that, if anyone doesn't mind sharing :)
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
I didn't read post #6 when you created it. It may be simpler to do a timer attachment (I have a similar method, if you'd like me to share). If you are insistent upon triggers, you could also attach a timer event to the trigger you pass to that function.
 

TheOverWhelm

Member
Reaction score
16
Timer Attachment? Whats the idea behind it?
I can attach a timerevent (if I understand you correctly), currently I'm able to do the
[t being the trigger and this.t being the timer]

On a sidenote, how does one do a single line of JASS like in those tutorials? The [] code part
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Timer Attachment? Whats the idea behind it?
I can attach a timerevent (if I understand you correctly), currently I'm able to do the
[t being the trigger and this.t being the timer]

That's a timer event, there's also the [ljass]TimerStart[/ljass] function (note that you can click that for a link to the function to see its arguments and return value), which allows you to pass a function to be called upon the timer's expiration. Timer attachment is essentially attaching a value, such as a struct instance, to the timer, so that when the timer expires, you have specific data attached to that timer. There are also timer systems, which use efficient algorithms to reduce the overhead of having multiple timers, which is common in maps with triggered custom spells.

On a sidenote, how does one do a single line of JASS like in those tutorials? The [] code part

You can use the [noparse][ljass][/ljass][/noparse] tags to make an inline jass tag (and you can display tags using the [noparse][noparse][/noparse][/noparse] tags.
 

TheOverWhelm

Member
Reaction score
16
Ahhh, I see. That's a neat thing to know for the future!
But I don't believe I can pass the instance number to that without have a loop to check which instance's timer expired..
Unless I use the timer systems available? Isn't that their purpose? Or is it for overhead?
Sorreh, I'm a bit newby to the vJASS community
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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