Jass help :P

Potatisbil

New Member
Reaction score
6
OK, let me first say that this is my first time using JASS :D

im having trouble with this custom script :
Code:
function Trig_Moo takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
      return false
    endif
    return true
endfunction

function Moo takes nothing returns nothing
    local unit Temp_Unit = GetTriggerUnit()
    call TriggerSleepAction( 2 )
    [COLOR="Red"]call CreateNUnitsAtLoc ( 1, 'hfoo', GetOwningPlayer(Temp_Unit), GetUnitLoc(Temp_Unit), bj_UNIT_FACING[/COLOR]
endfunction 

//===========================================================================

function InitTrig_Moo takes nothing returns nothing
    set gg_trg_Moo = CreateTrigger(  )
    [COLOR="red"]call TriggerAddAction( gg_trg_Moo, function Trig_Moo_Actions )[/COLOR]
endfunction
I get errors on the colored parts of the script.

On the first colored part i get this error :
"expected ' "

and on the 2nd colored part i get this one:
"Expected a function name"

can anyone telle me whats wrong? thanks in advance

~Potatisbil
 

SFilip

Gone but not forgotten
Reaction score
634
The first error line needs to be ended with a ) :rolleyes:
The second should be call TriggerAddAction( gg_trg_Moo, function Moo ) since you changed the function name. Also note that the condition function above is never used and your trigger doesn't have an event.
 

Potatisbil

New Member
Reaction score
6
Ah,ty :p added an event and fixed the problems :) thanks for yer help.

Another question: do you need to null local variables, and if so, how? :p (as said before, im veeery new to JASS)
 

SFilip

Gone but not forgotten
Reaction score
634
Yes, handle local variables (everything except for integer, real, string and boolean is a handle) need to be nulled, if set. You do this by simply setting the variable to null.
For example your function should be
Code:
function Moo takes nothing returns nothing
    local unit Temp_Unit = GetTriggerUnit()
    call TriggerSleepAction( 2 )
    call CreateNUnitsAtLoc ( 1, 'hfoo', GetOwningPlayer(Temp_Unit), GetUnitLoc(Temp_Unit), bj_UNIT_FACING
    set Temp_Unit = null
endfunction
Also your condition can be simplified.
Code:
function Trig_Moo takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
      return false
    endif
    return true
endfunction
change intro
Code:
function Trig_Moo takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
And change this:
Code:
function Moo takes nothing returns nothing
    local unit Temp_Unit = GetTriggerUnit()
    call TriggerSleepAction( 2 )
    call CreateNUnitsAtLoc ( 1, 'hfoo', GetOwningPlayer(Temp_Unit), GetUnitLoc(Temp_Unit), bj_UNIT_FACING
endfunction

Into this:
Code:
function Moo takes nothing returns nothing
    local unit Temp_Unit = GetTriggerUnit()
    local location [COLOR="Red"]l[/COLOR] = GetUnitLoc(Temp_Unit)
    call TriggerSleepAction( 2 )
    call CreateNUnitsAtLoc ( 1, 'hfoo', GetOwningPlayer(Temp_Unit), [COLOR="Red"]l[/COLOR], bj_UNIT_FACING
call RemoveLocation(l)
set Temp_Unit = null
endfunction

What you had is called a memory leak.
GetUnitLoc(Temp_Unit) will create a location variable, place the unit there.
Now a variable is created that will/can not be of use ever again.

So what we do is create a location variable ourselves, place the unit at that location, and remove the variable with call RemoveLocation(variable_name)

However locations are the only way to remove with RemoveLocation()
units and other things are done with set variable_name = null

You also forgot to nullify the temp unit. not remove/nullify it will again, stash up your computers memory. with useless information never to be used again.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
You forgot to set the local location to null, also.

Alternatively, this is much faster and better.

Code:
    local unit Temp_Unit = GetTriggerUnit()
    local real x=GetUnitX(Temp_Unit)
    local real y=GetUnitY(Temp_Unit)
    call CreateUnit(GetOwningPlayer(Temp_Unit) ,'hfoo' ,x ,y , 0)
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
You forgot to set the local location to null, also.

Alternatively, this is much faster and better.

Code:
    local unit Temp_Unit = GetTriggerUnit()
    local real x=GetUnitX(Temp_Unit)
    local real y=GetUnitY(Temp_Unit)
    call CreateUnit(GetOwningPlayer(Temp_Unit) ,'hfoo' ,x ,y , 0)

You dont have to nullify a removed location, thats already done in that action.
 
C

Capt Griffen

Guest
You do.

It causes the count to decrement for the handle index, allowing the handle index to count as clear, and thus stopping it from keeping the index pointing to a handle that no longer exists.

Or, alternatively, nullify for all non-permament handles.
 
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