HailCommi
New Member
- Reaction score
- 15
I'm trying to add a struct method that periodically updates member fields of itself. I originally had a method that keeps looping until it gets a stop signal, using a PolledWait for the interval. But I realized that the wait isn't short enough. Now I know I'm suppose to use timers for intervals smaller than 0.27, but then I need a function outside the structure, which prevents me from accessing members of that structure. Can someone help me work around this? Please and thanks ahead of time!
The code: (the problem is further down)
The code: (the problem is further down)
JASS:
struct Latch
boolean Active = false
integer Accelerated = 0
unit Target
timer Updater
real maxV = 999.0
real minV = 0
real MagnitudeOfAcceleration = 0
Cartesian Acceleration
Cartesian Velocity
real angularV = 0
real Payload = 1.0
real Mass = 1.0
real height = 0.0
boolean Volatile = false
CollisionInterface CollisionHandler
real CollisionSize = 1.0
//************Custom Values****************
boolean HaveWeapon = false
static method create takes CollisionInterface Collider, unit source, real mass, real payload, real Collision, real maxvel, boolean IsVolatile , real acc returns Latch
local Latch ret = Latch.allocate()
set ret.Updater = CreateTimer()
set ret.Mass = mass
set ret.Accelerated = 0
set ret.angularV = 0
set ret.Target = source
set ret.height = GetUnitFlyHeight(source)
set ret.Payload = payload
set ret.CollisionSize = Collision
set ret.maxV = maxvel
set ret.Volatile = IsVolatile
set ret.MagnitudeOfAcceleration = acc
set ret.Acceleration = Cartesian.create(0,0,0)
set ret.Velocity = Cartesian.create(0,0,0)
set ret.CollisionHandler = Collider
return ret
endmethod
method Collide takes nothing returns nothing
call this.CollisionHandler.evaluate(this)
endmethod
//====================================================
//==================================Problem Over Here====
//===================================================
method AccelerateLatch takes nothing returns nothing
loop
exitwhen (this.Accelerated == 0)
if (Magnitude(this.Velocity) < this.maxV) then
call this.Velocity.AddVector(this.Acceleration)
endif
set temp = GetUnitLoc(this.Target)
call SetUnitX(this.Target,GetLocationX(temp)+ this.Velocity.x)
call SetUnitY(this.Target,GetLocationY(temp)+ this.Velocity.y)
call RemoveLocation(temp)
call SetUnitFacing(this.Target,(GetUnitFacing(this.Target) + this.angularV))
call this.Acceleration.rotateCartesian(this.Acceleration.Theta + this.angularV)
call PolledWait(0.1) //<==========This Poll isn't long enough
endloop
endmethod
method StopAccelerateLatch takes nothing returns nothing
set this.Accelerated = 0
call SetUnitAnimation(this.Target, "Stand" )
endmethod
endstruct