| 08-21-2009, 02:25 PM | #1 |
Ok, I made a struct for creating trackables. I believe it's pretty inefficiently made, but I did my best. It uses ABC, but I want it to use Tables instead, but I'm not so good with them (I tried a few times). I think everything here is pretty much self-explanatory, so I hope you'll be able to help me. This "int" argument in the Code function interface means that the function passed to OnTrack and OnHit functions also take "int" and that is actually the Trackable struct, which is later converted with Trackable(int) typecasting. Any help will be much appreciated. JASS:private function interface Code takes integer int returns nothing struct Trackable trackable tc real x real y real z player p trigger tt = CreateTrigger() triggeraction tta Code ttc trigger ht = CreateTrigger() triggeraction hta Code htc static Table T static integer INT = 0 static method create takes string s, player p, real x, real y, real z returns Trackable local Trackable this = Trackable.allocate() local string t = "" local destructable d = CreateDestructableZ('OTip', x, y, z, 0.00, 1.00, 0) if GetLocalPlayer() == p then set t = s endif set this.tc = CreateTrackable(t, x, y, 0) set this.p = p set this.x = x set this.y = y set this.z = z set Trackable.T = Table.create() set Trackable.T[Trackable.INT] = this set Trackable.INT = Trackable.INT + 1 call TriggerRegisterTrackableTrackEvent(this.tt, this.tc) call TriggerRegisterTrackableHitEvent(this.ht, this.tc) call RemoveDestructable(d) set d = null return this endmethod private static method TrackActions takes nothing returns nothing local Trackable this = GetTriggerStructA(GetTriggeringTrigger()) call this.ttc.evaluate(integer(this)) endmethod private static method HitActions takes nothing returns nothing local Trackable this = GetTriggerStructA(GetTriggeringTrigger()) call this.htc.evaluate(integer(this)) endmethod method OnTrack takes Code C returns nothing set this.tta = TriggerAddAction(this.tt, function Trackable.TrackActions) set this.ttc = C call SetTriggerStructA(this.tt, this) endmethod method OnHit takes Code C returns nothing set this.hta = TriggerAddAction(this.ht, function Trackable.HitActions) set this.htc = C call SetTriggerStructA(this.ht, this) endmethod private method onDestroy takes nothing returns nothing call TriggerRemoveAction(this.tt, this.tta) call TriggerRemoveAction(this.ht, this.hta) call ClearTriggerStructA(this.tt) call ClearTriggerStructA(this.ht) call DestroyTrigger(this.tt) call DestroyTrigger(this.ht) endmethod endstruct |
| 08-24-2009, 05:18 PM | #2 |
C'mon, the code is not that big. Please? :D |
| 08-24-2009, 05:46 PM | #3 |
I'm not sure I really understand what you're asking anyone to do. All you do is a bunch of struct maneuvering and interfacing, there's not exactly much optimization to be had. If your problem is with your using ABC instead of table, table's documentation explains better than anyone else how to use it. Just replace your call SetTriggerStructA(this.tt, this) calls with set MyTable[GetHandleId(this.tt)] = this, while defining appropriate variables. Voillah, easy. You can also use handletables if you want with set MyHandleTable[this.tt] = this. |
| 08-25-2009, 11:15 AM | #4 |
I was asking for a better solution than that bunch of struct maneuvering and interfacing, because it looks pretty sloppy. And yeah, I wanted to replace ABC with Tables. Yeah, you're right, I just read my post and I realized I barely said anything about what I want at all. Ok, I got the Tables, the only problem now is that maneuvering :D |
