| 09-02-2007, 08:56 PM | #1 |
Hi. I was wondering, is it possible to attach structs to triggeractions (yes), and then reference the struct inside the triggeraction, based on what triggeraction is running? Example:struct Cache unit thing real stuff endstruct function Actions takes nothing returns nothing local Cache c=GetHandleInteger(GetRunningTriggerAction()) call SetWidgetLife(c.thing,c.stuff) endfunction function AddtoTrig takes unit u, real r, trigger t returns nothing local Cache c=Cache.create() local triggeraction ta=TriggerAddAction(t,function Actions) set c.thing=u set c.stuff=r call SetHandleInteger(ta,c) endfunction So that whenever trigger 't' runs, it will run 'Actions' once for each unit added, and the unit will differ based on what the handle of the triggeraction is? Is this even possible? -Thanks. |
| 09-02-2007, 09:28 PM | #2 |
you cant trace trigger actions if trigger have more then one. you have to create personal triggers |
| 09-02-2007, 09:32 PM | #3 |
Damn. There is no way to replicate this, then? |
| 09-02-2007, 09:33 PM | #4 |
There's no way to get the running triggeraction, but you could store each TriggerAction added and then loop through each of them and the appropriate structs. |
| 09-02-2007, 09:58 PM | #5 |
That sounds impractical. This is supposed to be a way of attaching multiple structs of different types to an instance of a struct. Any way of doing that? |
| 09-02-2007, 10:12 PM | #6 |
The first code is seems to be logically equivalent to using separate triggers, not really sure why you have to use separate triggeractions when a separate trigger does exactly the same thing |
| 09-02-2007, 11:03 PM | #7 |
Errr.... let's see if I can explain this... I have a struct, which stores a unit, its owner and 4 triggers. On struct creation, the unit is created with the parameters given, and the 4 triggers are created. Each gets an event registered based on what the name of the trigger is: JASS:struct hero unit hero player owner trigger pickup trigger use trigger order trigger drop static method Pickup takes nothing returns nothing local hero h=HashtableA.get(H2I(GetTriggeringTrigger())) if(IsBag(GetManipulatedItem()))then call BagAddActions(h,GetManipulatedItem()) endif endmethod static method Drop takes nothing returns nothing local hero h=HashtableA.get(H2I(GetTriggeringTrigger())) if(IsBag(GetManipulatedItem()))then call BagRemoveActions(h,GetManipulatedItem()) endif endmethod static method create takes player p, integer id, real x, real y, real face returns hero local hero h=hero.allocate() set h.hero=CreateUnit(p,id,x,y,face) set h.owner=p set h.pickup=CreateTrigger() set h.use=CreateTrigger() set h.order=CreateTrigger() set h.drop=CreateTrigger() call HashtableA.put(H2I(h.pickup),h) call HashtableA.put(H2I(h.use),h) call HashtableA.put(H2I(h.order),h) call HashtableA.put(H2I(h.drop),h) call TriggerRegisterUnitEvent(h.pickup,h.hero,EVENT_UNIT_PICKUP_ITEM) call TriggerRegisterUnitEvent(h.use,h.hero,EVENT_UNIT_USE_ITEM) call TriggerRegisterUnitEvent(h.order,h.hero,EVENT_UNIT_ISSUED_TARGET_ORDER) call TriggerRegisterUnitEvent(h.drop,h.hero,EVENT_UNIT_DROP_ITEM) call TriggerAddAction(h.pickup,function hero.Pickup) call TriggerAddAction(h.drop,function hero.Drop) return h endmethod endstruct pickup and drop both get actions added to them. When the hero picks up an item, then, if it is a bag, BagAddActions(hero,item) is run. This adds everything the bag needs to function into the hero's 4 triggers. The thing is, the triggers need to know what bag the actions are for to function correctly (the used/dropped item won't always be a bag), so, in order to keep all the information needed from the bag item, it must be attached to the created triggeractions, creating 'dynamic' actions. On Drop, if the item is a bag, BagRemoveActions(hero,item) is run. This removes the triggeractions from the hero's triggers. I just need a workaround to get what triggeraction is running, and this whole thing will work. |
| 09-02-2007, 11:18 PM | #8 |
well, since you can't get triggering trigger action, just have some sort of array holding all bags, it will be healthier anyways since that way you won't need to get into more attach hell than you need to. |
| 09-02-2007, 11:25 PM | #9 | |
I actually have an array of all bags. It's called a struct. Even if I had an array, how would I know which index to use, without attachment of some sort? I am reluctant to post absolutely all of the code in which this is needed - even I think it gets confusing sometimes. Meh. View at your own risk:
|
| 09-02-2007, 11:32 PM | #10 | |
Quote:
When a trigger is executed it will run all its triggeractions without any discrimination. If you have an array that holds all the bags owned by the hero then ... just a single loop that will process all the bags owned by the hero when the trigger is executed will do the work, it is exactly the same as having a trigger action per bag and attaching a bag id for each trigger action, only that it will be much faster |
| 09-02-2007, 11:44 PM | #11 |
But, hero is a struct. Bag is a struct. I could have a bag array, but there really isn't a limit to the number of bags a hero can have (actually, I guess it would be 126, since each bag can hold 20 items, and the hero has 6 slots, but that slices the instance limit of hero down to 65, which is really dumb), and there are other types of item holders too. The idea of using static method and trigger actions was to have everything needed for a bag to be contained within the struct bag. EDIT: Argh. I hate it when Vex is right. Now, I am simply disregarding any sort of bag looping - everything is done dynamically. Although perhaps it is not the fastest thing in the world, my instances have jumped up from 65 to 1365, which is much less dumb. I am kinda happy with my ability to be uber, and devise clever yet simple methods of solving problems. |
| 09-03-2007, 11:21 AM | #12 |
Holy crap somebody copied my insane idea of pitems. I'm impressed. I'm not even mad. I thought pitems were a terrible idea, but somebody bothered to try it. The way I'm handling bags now is using my itemMenu interface engine. Since all bags act exactly the same the only thing that really changes is the addCondition, and the size. Which I don't handle yet as itemVector is a static 12 until I think of a better way to do IVs. (I'm guessing link-lists of 4 items at a node but thats still terrible). I still could do gc but its much more humanely readable code wise. Alternatively you could just add a simple currentBag variable. And on open just do... JASS:local hero h=GetTriggerUnit() set h.currentBag=GetManipulatedItem() |
| 09-03-2007, 01:26 PM | #13 |
If you were worried about instance limits you could have just used a linked list. Get real, no player is ever gonna appreciate the experience of owning 126 bags. Even a limit of 5 bags per hero is going to work... edit: 65 heroes is yet another huge instance limit anyways... If each player had 3 heroes that would be 36 heroes? You would need to think of giving each player 6 heroes to break this limit... SIX heroes! |
| 09-03-2007, 01:29 PM | #14 | ||
Actually yeah, I love pitems. They make most of this code really easy for me to write. Hero is still an object, and, when you create it, he still gets the four triggers. Each of the triggers is a single unit event, so, I know which hero ran it, so I attach the hero directly to each trigger. I do have a current bag variable. It's called openbag. It only applies if the hero is currently in the bag. Otherwise, it's 0 (since bag is a struct as well). The reason I don't use GetManipulatedItem() to get the bag is because stuff happens with the bag even if the item isn't the bag. Yay! Note: Bag size is static for me too. I am thinking of wrapping bag with textmacros, so you can call: //! runtextmacro CreateBag("name","cap") EDIT: Yeah, originally, I didn't see a problem with an instance limit for heros. It just had to at maybe 12-24. Any more, and the players aren't getting the experience I wanted for a hero - lots of managing. Bag was a bigger issue. I was worried about failures. Sure, nobody would ever WANT 126 bags, but, if they got them all, then 'bag' would start failing. And that's something I don't want. EDIT 2: Gaaargh. Just for the sake of posting code, I am posting my revised code:
|
