Need Help again: Struct methods that updates it's own fields periodically

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)

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
 

Executor

I see you
Reaction score
57
Hm, the best way to do this, in your case, is to link all of your structs via a linked list and loop them periodically with one global timer.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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