Couple of weird syntax errors:

Technomancer

New Member
Reaction score
14
Hey, the code so far is ugly, but this is for a new timer system that I'm working on.

JASS:
// These functions and structs are the core of the hit n' run library.
// 
// DOCUMENTATION
// I'm generally bad at documentation so please, if you would like anything explained,
// please, PM me @Technomancer on <a href="http://www.thehelper.net" class="link link--internal">www.thehelper.net</a>, and I&#039;ll add it to the documentation
// 
// ***************************************************************************************
// The general idea is to run your map according to a global timer, instead of creating
// and destroying any number of individual timers, because as a rule we try to cut down
// on trigger events and function calls during the execution of a map, and CreateTimer(),
// DestroyTimer(), and espeically TimerStart(...) and the associated triggers will lag your
// shit up, that&#039;s a gaurentee.  Several maps already incorporate global event timers into
// themselves, this is just a premade package that will allow you to easily do so in your 
// map.
// 
// ***************************************************************************************
// This trigger set uses vJass.  The only other effective system for doing this sort of 
// would be to use gamecache based handle var systems, which in rare cases are buggy,
// but can also slow the game excessively.
//
// ***************************************************************************************
//
// This is how this pacakage will create new timer operated units:
// Step 1) Create a Unit
// Step 2) Create a timer structure (Techno_TimerUnitOnTimerHandle)
// Step 3) Assign a struct of type Techno_GunUnitAttach to the unit&#039;s custom value
//               using ABC attachment system
// Step 4) Create a function with the following arguements:
//            function NAME takes unit interface_unit returns nothing
// Step 5) Assign the unit and an associated function to the timer
//               the timer can now automatically pick out the unit&#039;s necessary 
//               custom values from the attached
//        &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;
//      EXAMPLE
//        call YOUR_TIMER_STRUCT_NAME.Timer_Add_Unit( YOUR_UNIT_NAME, UNIT&#039;S_FUNCTION_NAME )
//        Obviously, replace the stuff in all caps with your names
//        &#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;&#039;               
// Step 5) Activate the timer if necessary.  The timer will automatically pass the unit
//               to the required function.
// Step 7) Any additional data you wish to pass can be passed in the structure you
//         assigned in the Unit&#039;s custom value.  This allows total modularity, because
//         any function that can access the unit can access all of the values that are
//         involved in the function
//                
//
//         I would love some help textmacroing this up to be more modular, so that the unit
//         can take differently named structs, and the function interface can take different
//         arguements if the user so desires.


globals
constant integer MAX_UNITS = 64
endglobals

function interface INTERFACE takes unit interface_unit returns nothing

struct Techno_TimerUnitOnTimerHandle
    private timer T_Timer = CreateTimer()
    private unit array Unit_Array[MAX_UNITS]
    private INTERFACE array Unit_Funcs_Array[MAX_UNITS]
    private real cooldown = .01
    private integer Num_Units = 0
    
    method Timer_Add_Unit takes unit u, INTERFACE f returns nothing
        if (this.Num_Units &lt;= MAX_UNITS) then
            set this.Unit_Array[this.Num_Units] = u
            set this.Unit_Funcs_Array[this.Num_Units] = f
            set this.Num_Units = this.Num_Units + 1
        else
            call BJDebugMsg(&quot;Unit Cap Reached on Timer&quot;)
        endif
        set u = null
    endmethod
    method Timer_Get_Last_Unit takes nothing returns unit
        local unit u = this.Unit_Array[this.Num_Units]
        return u
    endmethod
    method Timer_Remove_Last_Unit takes nothing returns nothing
        set this.Unit_Array[this.Num_Units] = null
        set this.Num_Units = this.Num_Units - 1
    endmethod
    
// ***AWAITING IMPLEMENT***    
    method Timer_Remove_Unit_Enum takes integer unum returns nothing
        //This one could use rescripting...
    endmethod
    
    
    //This function is the function on the timer trigger
    method Timer_Action_Functions takes nothing returns nothing
    local integer i = 0
    local unit u
    local Techno_GunUnitAttach gattach = Techno_GunUnitAttach.create()
    local INTERFACE f
    loop
        exitwhen i &gt; this.Num_Units
            //Get Function Attached GunStruct
            set u = this.Unit_Array<i>
            set gattach = GetUnitUserData(u)
            //***AWAITING IMPLEMENT***
            //***CHECK COOLDOWN OF UNIT TRIGGER***
                //Get associated function of gunstruct
                set f = this.Unit_Funcs_Array<i>
                call f.execute(u)
                set i = i + 1
        endloop
    set u = null
    endmethod
    method Timer_SetCooldown takes real cd returns nothing
        set this.cooldown = cd
    endmethod
    
    //***AWAITING IMPLEMENT***
    //For some reason, the following line of code bugs.
    method Timer_TimerStart takes nothing returns nothing
//        call TimerStart(this.T_Timer, this.cooldown, true, this.Timer_Action_Functions)
    endmethod
    
endstruct

struct Techno_GunUnitAttach
    integer timercounter //counts timer iterations
    integer projectile_unit
    //targetting declares
    integer targetting_function_type = 2
    unit targ1_targettingunit
    real targ2_fixedx
    real targ2_fixedy
    real targ3_angle
    
    method SetProjectileType takes integer UnitType returns nothing
        set this.projectile_unit = UnitType
    endmethod

    method GetProjectileType takes nothing returns integer
        return this.projectile_unit
    endmethod
    
    method GetTimerCounter takes nothing returns integer
        return this.timercounter
    endmethod
    
    method GetTargLocX takes nothing returns real
        if (this.timercounter == 1) then
            return GetUnitX(this.targ1_targettingunit)
        elseif (this.timercounter == 2) then
            return this.targ2_fixedx
        endif
        return 0.
    endmethod
    
    method GetTargLocY takes nothing returns real
        if (this.timercounter == 1) then
            return GetUnitY(this.targ1_targettingunit)
        elseif (this.timercounter == 2) then
            return this.targ2_fixedy
        endif
        return 0.
    endmethod
    
    method GetTargFixedAngle takes nothing returns real
        return this.targ3_angle
    endmethod
    
    method CalcTargAngle_targ1 takes real sourceX, real sourceY returns real
        return (bj_RADTODEG * Atan2( (GetUnitY(this.targ1_targettingunit) - sourceY ), (GetUnitX(this.targ1_targettingunit) - sourceX) ))
    endmethod
    
    method CalcTargAngle_targ2 takes real sourceX, real sourceY returns real
        return (bj_RADTODEG * Atan2( (this.targ2_fixedy - sourceY ) , ( this.targ2_fixedx - sourceX ) ) )
    endmethod

    method GetTargUnit takes nothing returns unit
        return this.targ1_targettingunit
    endmethod
    
    method GetTargFuncType takes nothing returns integer
        return this.targetting_function_type
    endmethod

//    method SetProjectileTargType takes integer t returns null
//    set this.targetting_function_type = t
//    endmethod

    method Init takes unit u, integer i returns nothing
        set this.targetting_function_type = i
        set this.timercounter = 0
        set this.projectile_unit = &#039;nfro&#039; //make sure to change this if your shit is coming out in frogs, dumbass.
        set this.targ2_fixedx = 0.
        set this.targ2_fixedy = 0.
        set this.targ3_angle = 0.
    endmethod
endstruct

library TechnoGunSystem uses ABC
    function TGSLinearMove takes unit interface_unit returns nothing
        //Move unit in a straight line according to distance every tick
    endfunction
    
    function TGSArcMoveByAngle takes unit interface_unit returns nothing
        //Move unit and adjust move angle each time.
    endfunction
    
    function TGSArcMoveByDxDy takes unit interface_unit returns nothing
        //Move unit in an arc pattern, and use distance modifiers instead of angle modifiers
    endfunction
    
    function TGSMathFuncMove takes unit interface_unit returns nothing
        //Move unit following a mathematical function.
    endfunction
    
    function TGSLinearMove_AdjustWithMathFunc takes unit interface_unit returns nothing
        //Moves unit following the path of a straight line, and adjusts the pathing of the unit using a mathematical function
    endfunction

    function TGSCollision_Detect takes unit interface_unit returns nothing
        local trigger trig = GetTriggeringTrigger()
        //Get applicable units
        //Get EFFECTS functions
        //Apply EFFECTS to target
        //Clean Up Trigger
        //Remove Triggering Unit from the Game
    endfunction
endlibrary</i></i>


First syntax error:
JASS:
    //***AWAITING IMPLEMENT***
    //For some reason, the following line of code bugs.
    method Timer_TimerStart takes nothing returns nothing
//        call TimerStart(this.T_Timer, this.cooldown, true, this.Timer_Action_Functions)
    endmethod


Second syntax error:
JASS:

//    method SetProjectileTargType takes integer t returns null
//    set this.targetting_function_type = t
//    endmethod


The appropriate crap is commented out right now, however, for the first one, I'm stumped, for the second one, I'm stumped.

Import this and ABC into a map, uncomment, and try to compile to see what I mean.
 

SFilip

Gone but not forgotten
Reaction score
634
In the first you're using a method for timer callback, that won't work unless this method is static.
In the second you wrote returns null instead of returns nothing. You should also know that it's pointless to use a method just to set a variable like that, methods are in fact slow compared to simply doing it "manually".
 

Technomancer

New Member
Reaction score
14
Ok, so I changed the method to a static method, and it didn't work, can you explain what you meant by static methods? This script is starting to come around but I gotta be able to start the timer to test anything.

Further testing reveals that I might be boned and have to make alot of jumps in and out of the struct instance.
 

SFilip

Gone but not forgotten
Reaction score
634
Static methods are methods not bound to a specific struct, you can't use this. inside them.
They're basically like using a normal function, but with a fancy name and that can be accessed from anywhere.
Example
Code:
struct test
   integer foo
   static method bar takes nothing returns nothing
   endmethod
endstruct

function runme takes nothing returns nothing
     call [B]test[/B].bar()
endfunction
Notice that it's used without any struct being created, just with <structname>. in front of it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top