HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Questions About JASS

05-10-2006, 06:39 AM#1
poz
1. About memory leaking when using function that needs point(location)
I know that we need to assign a location to a variable and destroy it when don't want to use it anymore. But what should I do when I assign it using a function that need a point as agrument?

Example (I using Vexorian's Caster System function)
Collapse JASS:
    set loc = PolarProjectionBJ(GetUnitLoc(GetTriggeringUnit()), 600.00, angle)
    call CasterCastAbilityLevelPointLoc( owner, abilid, level, order, loc, false )
    call RemoveLocation( loc )

Will this cause memory leak? Or should i do this:
Collapse JASS:
    set caster = GetUnitLoc(GetTriggeringUnit())
    set loc = PolarProjectionBJ(caster, 600.00, angle)
    call CasterCastAbilityLevelPointLoc( owner, abilid, level, order, loc, false )
    call RemoveLocation( caster )
    call RemoveLocation( loc )



2. If I create alot local variables to call a function everytime when a hero cast a spell, will it cause lag when doing it on every spell?
Should I do this(create alot local variables)
Collapse JASS:
    
    local player owner = GetOwningPlayer(GetSpellAbilityUnit())
    local integer abilid = 'A00M'
    local integer level = GetUnitAbilityLevelSwapped('A03P', GetSpellAbilityUnit())
    local string order = "unholyfrenzy"
    local widget target = GetSpellAbilityUnit()

    call CasterCastAbilityLevel( owner, abilid, level, order, target, true )

Or this(just put everything straght in)..
Collapse JASS:
    
   call CasterCastAbilityLevel( GetOwningPlayer(GetSpellAbilityUnit()), 'A00M', GetUnitAbilityLevelSwapped('A03P', GetSpellAbilityUnit()), "unholyfrenzy", GetSpellAbilityUnit(), true )

3. What is the different between normal function and constant function? The demo map of Caster System uses "constant function" on some of the spells but I dont get an idea the different between that and normal "function".
05-10-2006, 08:09 AM#2
The)TideHunter(
Things that are created in a function need to be set as global or local varaibles, like points, but the unit you are refering to is already created, your just pointint to it.
So using everything in the same line is good, but only some things need to be stored.

Only your point needs to be stored localy in your code.
Strings are not leaky, some people say they 'leak once', but thats normal.
Widgets and integers are fine, unless you create them and dont assign them to something.

The only thing i can see is the point, so this is the correct code:

Collapse JASS:
    set loc = PolarProjectionBJ(GetUnitLoc(GetTriggeringUnit()), 600.00, angle)
    call CasterCastAbilityLevelPointLoc( owner, abilid, level, order, loc, false )
    call RemoveLocation(loc)
05-10-2006, 10:04 AM#3
poz
So for my situation above all I have to do is just store my point into a local variable. And call the function with everything in a line?

Btw maybe the code blocks my another question:
What is the different between "constant function" and "function"?
05-10-2006, 10:16 AM#4
sheep.spirit
If i am not wrong you have to nullify that one as well, as you have used that location, even for inside a function, it is still being called meaning it will take up space and have leaks. Correct me if i am wrong, cause that time i thought you can just do that, but Vex corrected me
05-10-2006, 11:13 AM#5
poz
Er.. i'm confused now... What I suppose to do then?
05-10-2006, 11:44 AM#6
Vexorian
object leaks are not about arguments they are about return values.

You don't have to care about functions that just take a location argument, you have to care about functions that return a location.

Most of the times you can be sure that if a function returned a location it created one and then you have to remove the location.

For example GetUnitLoc() Location(...,..) and PolarProjectionBJ

Also when you use local variables of handle types you better set them to null before the function ends

Collapse JASS:
     set loc=null

It is actually becase of a lame bug with the engine
05-10-2006, 02:40 PM#7
The)TideHunter(
And for your other question about constants and non-constants:

As i now of:

Constant functions are a function that will never be changed, they return a variable, but can take them too, this is because the game remembers the actions instead of doing them again.
example:

Collapse JASS:
constant function SuperSpellAbilityId takes nothing returns integer
    return 'A000'
endfunction

another:

Collapse JASS:
constant function SuperSpellDamage takes integer level returns real
    return lvl * 50 + 100
endfunction

And ofcourse, you know about normal functions, they do whatever and can be changed, constants are just really 'standard coding'.

Collapse JASS:
function HaveSomeFun takes nothing returns nothing
    call DoNothing()
endfunction

function DoNothing takes integer GrassLength, string PlayerHairLength returns gamecache
    call DoNothing()
    call DoNothing()
    call HaveSomeFun()
    return null
endfunction
They also help, as in JESP standard.
If you saw a constant in a spell, it basicly means change it to what you like, but in normal functions, they should not be edited.

Im sorry if this is confusing, their are many reasons for constants

EDIT: To use constants, just use them like normal

Collapse JASS:
function SuperSpellDamage takes integer lvl returns real
    return lvl * 50 + 100
endfunction

function DamageAUnitWithSuperSpell takes unit whichUnit returns nothing
    local real damage = SuperSpellDamage(GetUnitLevelOrWhatever(whichUnit))
    call DamageTheUnit(whichUnit, damage)
endfunction