• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Triggers Inside Structs

Status
Not open for further replies.
Level 5
Joined
Aug 16, 2007
Messages
149
I'm currently making a system which could be made much easier by creating a function using methods to create triggers inside structs. I was just wondering if that's possible?
 
Level 5
Joined
Aug 16, 2007
Messages
149
omg... I just tried it like this:
JASS:
struct myStruct
    trigger t
    method Trigger_Actions takes nothing returns nothing
        //do stuff
    endmethod

    method Init_Trig_Trigger takes nothing returns nothing
        set .t = CreateTrigger()
        call TriggerAddAction(.t, function s__myStruct_Trigger_Actions)
    endmethod

    static method Create takes nothing returns nothing
        local myStruct s = myStruct.create()
        call s.Init_Trig_Trigger()
    endmethod

endstruct
and 1 problem came out of it: Trigger_Actions can not take or return any values! Because JassHelper compiled it like this:
JASS:
    method s__myStruct_Trigger_Actions takes integer this returns nothing
        //do stuff
    endmethod
How the heck do I solve this other than creating a seperate function for it thus ruining MUI?????!!!!!

EDIT:
Sorry, that may sound a bit angry and demanding. Let me rephrase that: could someone please help me sort out this problem and help me write this script MUI?
 
Last edited:
Level 9
Joined
Mar 25, 2005
Messages
252
[jass=I believe this is what you want]struct myStruct
trigger t
static method Trigger_Actions takes nothing returns boolean
local myStruct this = GetAttachedStruct1(GetTriggeringTrigger())
//do stuff
return false
endmethod
method Init_Trig_Trigger takes nothing returns nothing
set .t = CreateTrigger()
call AttachStruct1(.t, this)
call TriggerAddCondition(.t, Filter(function myStruct.Trigger_Actions))
endmethod
static method Create takes nothing returns nothing
local myStruct s = myStruct.create()
call s.Init_Trig_Trigger()
endmethod
endstruct[/code]

You need HSAS for this to work.
 
Level 5
Joined
Aug 16, 2007
Messages
149
kk trying that now

EDIT:
for some reason even static functions take 'this'! Oh well I'll just do it with a seperate function, but run 2 seperate textmacros for each trigger... It's the only way I suppose (unless someone can think of another)

EDIT:
Aaargh I can't do that since functions can't find 'myStruct' if they're above it and inits can't find actions if they're below the struct!!!

EDIT:
lol sorted by using myFunction.execute()...

EDIT:
... says myFunction is not of a type that allows '.' syntax when I do myFunction.execute()!!! Help please!
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
I use triggers in structs all the time, so don't lose hope. Could you post your current code, bubba_ex?

Edit: Maybe this will help:
JASS:
struct MyStruct
    trigger trig
    triggercondition c
    triggeraction a
    private method CleanTrigger takes nothing returns nothing
        call TriggerRemoveCondition(.trig,.c)
        call TriggerRemoveAction(.trig,.a)
        call DestroyTrigger(.trig)
    endmethod
    static method Conditions takes nothing returns boolean
        return true //whatever conditions
    endmethod
    static method Actions takes nothing returns nothing
        local MyStruct data = GetTriggerStructA(GetTriggeringTrigger()) //retrieve the struct
        call data.CleanTrigger() //must clear the conditions and actions before using
        call DoNothing()//whatever actions
    endmethod
    static method create takes nothing returns MyStruct
        local MyStruct data = MyStruct.allocate()
        set data.trig = CreateTrigger()
        call SetTriggerStuctA(data.trig, data) //I used ABC, just attach it somehow
        call TriggerRegisterUnitEvent(data.trig,GetTriggerUnit(),EVENT_UNIT_DAMAGED) //whatever event you need
        set data.c=TriggerAddCondition(data.trig,Condition(function MyStruct.Conditions)) //triggerconditions must be removed
        set data.a=TriggerAddAction(data.trig,function MyStruct.Conditions) //so must triggeractions
        return data
    endmethod
endstruct 

function Trig_MyStruct_Actions takes nothing returns nothing
    local MyStruct data = MyStruct.create()
endfunction

//===========================================================================
function InitTrig_MyStruct takes nothing returns nothing
    set gg_trg_MyStruct = CreateTrigger(  )
    call TriggerAddAction( gg_trg_MyStruct, function Trig_MyStruct_Actions )
endfunction

Also, here's a link to part of my tutorial which is a work-in-progress. The section on methods explains a bit on how to use a custom create method.
 
Last edited:
Level 5
Joined
Aug 16, 2007
Messages
149
> poot
If a trigger is inside a struct, it would make it much easier to handle from within the struct.

>blue_jeans
I already tried making the actions and conditions static, but it didn't work for some reason, still took 'integer this' apparently. But I suppose I might have done it wrong. I'll try it again.

EDIT:
.blue_jeans
Wtf? It worked this time! Why didn't it work before? Oh well ty and +rep.
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
Why would you want a trigger inside a struct, in that sense, anyways? It makes no difference.

An attack-detection trigger? use the first to trigger an attack, and the second (auto-created one) detect damage? I have other examples, but they are very specific. I did one for Flame_Pheonix the other day that dealt with timers and regions and such.
 
Level 5
Joined
Aug 16, 2007
Messages
149
no it isn't an attack detection trigger it's a 3D movement struct and controlled via arow keys, hence the triggers.
 
Level 6
Joined
Jun 30, 2006
Messages
230
I was just giving PurplePoot a few examples of what you would use this for. Yours is another reason, possibly. Never tried doing anything attached to arrow keys...
 
Status
Not open for further replies.
Top