• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Moving in a Circle (ABC)

Status
Not open for further replies.
Level 3
Joined
Dec 29, 2006
Messages
15
Hello, I'm trying to learn how to use ABC struct attachments, and Jass and I've been trying to make this trigger move the casting unit in a circle. However it hasn't been working; anyone know why?

JASS:
scope BoomerangABC

globals
    constant integer AID_BOOMERANGABC = 'A000'
endglobals

globals  
    private constant real PERIOD = 0.04
    private constant real SLIDE_SPEED = 600. 
endglobals 

private struct SpellData
    unit boomerangcaster
    real distance
    integer ticks
    location radius
    real angle = 0.0
endstruct

private function Timer_Actions takes nothing returns nothing  
    local integer i = 1 
    local SpellData data 
    local real x 
    local real y 
    local location temppoint
    local timer t = GetExpiredTimer()
    
	set data = GetTimerStructA(t)  
    
    set data.angle = (data.angle +(360/ (SLIDE_SPEED*PERIOD)))
	
    set temppoint = PolarProjectionBJ(data.radius, data.distance, data.angle)
    set x = GetLocationX(temppoint)
    set y =GetLocationY(temppoint)
    call SetUnitPosition(data.boomerangcaster, x, y)

    set data.ticks = data.ticks - 1
    if data.ticks <= 0 then  
        call SetUnitPathing( data.boomerangcaster, true )
		call PauseUnit( data.boomerangcaster, false )
        call data.destroy()  
		call ClearTimerStructA(t) // We must clear attachments before destroying timer
        call DestroyTimer(t)
    endif  
endfunction

private function Actions takes nothing returns nothing  
    local SpellData data = SpellData.create() 
    local location target = GetSpellTargetLoc()
    local timer t = CreateTimer()
    local real Dx
    local real Dy
    local real angle
    
    set data.boomerangcaster = GetTriggerUnit()
    
    set Dx = GetLocationX(target) - GetUnitX(data.boomerangcaster)
    set Dy = GetLocationY(target) - GetUnitY(data.boomerangcaster)
    
    set data.distance = ((SquareRoot(Dx * Dx + Dy * Dy))/2) //calculates distance of radius 
    set angle = AngleBetweenPoints(target, GetUnitLoc(data.boomerangcaster))  
    set data.radius = PolarProjectionBJ(target,data.distance, angle)//calculates center of circle  
    call RemoveLocation(target)
    
    set data.ticks = R2I(data.distance / (SLIDE_SPEED*PERIOD))
    
    call SetUnitPathing( data.boomerangcaster, false )
    call PauseUnit( data.boomerangcaster, true)

    // attaching a struct to a timer
    call SetTimerStructA(t, data)
    call BJDebugMsg(udg_w)
	
    call TimerStart(t,PERIOD,true,function Timer_Actions)

    set t = null
endfunction 

//===========================================================================
private function SpellComparision takes nothing returns boolean
    return GetSpellAbilityId() == AID_BOOMERANGABC
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing  
    local trigger trig = CreateTrigger()  
    
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )

    call TriggerAddCondition( trig, Condition( function SpellComparision ) )
    call TriggerAddAction( trig, function Actions) 
endfunction 

endscope
 
Last edited:
Level 11
Joined
Aug 25, 2006
Messages
971
Since Eleandor isn't online, I'll have to say it for him.

Tell us what you've tried.
What doesn't work.
And What your trying to do!


Adding comments to your code increases our ability to help as well.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
I haven't read the code at all, but shouldn't the scope use requires ABC?

EDIT: Nevermind, I'm an idiot. I never use ABC anyway. Please don't read this :p

EDIT2: Wow that's a ridiculously unefficient script. I think I'll re-make it.

EDIT3: Too tired, got to go to sleep. I might do it tomorrow.
 
Level 11
Joined
Aug 25, 2006
Messages
971
Ok, doesn't a 'scope' make everything inside it private? In that case whats the point of declaring the constants as private?
 
Level 11
Joined
Feb 18, 2004
Messages
394
Ok, doesn't a 'scope' make everything inside it private? In that case whats the point of declaring the constants as private?

no.

inside a scope or library, anything you declare is in the global scope. (not prefixed)

"public" causes something to be prefixed with the scope name, such as:
JASS:
scope A
globals
    public integer i
endglobals
endscope
when using i outside A, you must refer to it as A_i. Public is mostly useful for libraries.

Private prefixes all things with a randomly generated string, preventing them from being accessed by default outside of the scope / library.


Also, Hindy, scopes can't require / use / needs anything, only libraries can. (as that is how you control the order in which libraries come at the top of a script) Scopes are always below libraries in the script anyway. Thus they have access to all public / non prefixed members of any libraries.
 
Status
Not open for further replies.
Top