HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Dummy caster function

08-19-2007, 04:54 PM#1
Castlemaster
I'm trying to make dummy caster functions that I can call upon to consolidate some of my code. This is my dummy function for spells with no target

Collapse JASS:
function DummyCasterNoTarget takes unit caster, location l, integer dummyspellID, integer herospellID, string spellcommand returns nothing
    call CreateNUnitsAtLoc( 1, 'n00G', GetOwningPlayer(caster), l, bj_UNIT_FACING )
    call RemoveLocation (l)
    call UnitApplyTimedLifeBJ( 2.00, 'BTLF', GetLastCreatedUnit() )
    call UnitAddAbilityBJ( dummyspellID, GetLastCreatedUnit() )
    call SetUnitAbilityLevelSwapped( dummyspellID, GetLastCreatedUnit(), GetUnitAbilityLevelSwapped(herospellID, GetSpellAbilityUnit()) )
    call IssuePointOrderLocBJ( GetLastCreatedUnit(), spellcommand, GetRectCenter(GetPlayableMapRect()) )
endfunction

I tried to call this function from a different trigger (they are not in the same trigger) using this line of code

Collapse JASS:
    call function DummyCasterNoTarget(u, target, A010, A01P, "thunderclap")

I keep getting a syntax error, why is that? (i'm new to JASS, JASSnewb here, etc. etc.)

Thanks ahead of time.
08-19-2007, 05:14 PM#2
TaintedReality
Collapse JASS:
call function DummyCasterNoTarget(u, target, A010, A01P, "thunderclap")

When you call a function you don't put "function" before its name. Also, object id's need to have ' around them. So it would be:

Collapse JASS:
call DummyCasterNoTarget(u, target, 'A010', 'A01P', "thunderclap")

You just put function before the name when you're declaring it, or when you have to use it as a code variable (as when you're passing it to the TimerStart function or something).

Oh and btw, I didn't look at the actual function so there might be issues there ; ).
08-19-2007, 07:54 PM#3
Dil999
Firstly, try to avoid anything using points. That means instead ofusing CreateNUnitsAtLoc you would use CreateUnit. Since you cant use bj_LastCreatedUnit when using CreateUnit, you need to make a local unit and set that local unit to the created unit, like this:
Collapse JASS:
local unit u = CreateUnit(GetOwningPlayer(caster),'n00G',x,y,270.0)

Second, instead of using UnitApplyTimedLifeBJ, use UnitApplyTimedLife. They are the same thing except the non-bj one is slightly faster and takes things in a different order.

Also, use UnitAddAbility instead of UnitAddAbilityBJ. Theyre the same thing except they take things in a differnet order.

Use SetUnitAbilityLevel instead of SetUnitAbilityLevelSwapped. Same thing, except SetUnitAbilityLevel takes things in a different order and is faster.

Finally, you want to use IssueImmediateOrder if your spell has no target.

Here is the new trigger:

Collapse JASS:
function DummyCasterNoTarget takes unit caster, real x, real y, integer dummyspellID, integer herospellID, string spellcommand returns nothing
    local unit u = CreateUnit(GetOwningPlayer(caster),'n00G',x,y,270.0)
    call UnitApplyTimedLife(u,'BTLF',2)
    call UnitAddAbility(u,dummyspellID)
    call SetUnitAbilityLevel(u,dummyspellID,GetUnitAbilityLevel(caster,herospellID))
    call IssueImmediateOrder(u,spellcommand)
    set u = null
endfunction
08-20-2007, 08:41 AM#4
Av3n
Add
Collapse JASS:
 u = null 
as well to that code that Dil999 at the end of it

-Av3n
08-20-2007, 08:43 AM#5
Dil999
Whoops, thanks for that.
That post just pushed me to the harsh realization that I haven't been clearing leaks in any trigger I've done for the past week..
08-20-2007, 02:36 PM#6
Castlemaster
Thanks for the help guys.
Out of curiosity what the deuce is the whole BJ vs. non-BJ thing?
08-20-2007, 03:41 PM#7
uberfoop
BJ's are basically functions that work like any function you write up; it has a function bleh takes bleh returns bleh at the start and an endfunction at the end and a bunch of code in between.
Native functions (non-BJ's) are the basic functions that in the end actually DO everything. Example:
This is the native function Sin. It takes radians:
Code:
native Sin takes real radians returns real
That is BJ function SinBJ.
Code:
function SinBJ takes real degrees returns real
    return Sin(degrees * bj_DEGTORAD)
endfunction
Within SinBJ, it has the native Sin function called, along with a *bj_DEGTORAD to convert the degree value that the function asks for to radians, because the Sin native uses radians.

BJ's are often thought to be evil because you can generally accomplish the exact same thing using purely natives which, because in the end less overall function calls have been made, is in the end more efficient than useage of BJ's.
08-20-2007, 06:31 PM#8
Pyrogasm
In addition, many BJ's are absolutely pointless:
Collapse JASS:
function AttachSoundToUnitBJ takes sound soundHandle, unit whichUnit returns nothing
    call AttachSoundToUnit(soundHandle, whichUnit)
endfunction

And some are somewhat useful:
Collapse JASS:
unction TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
    local integer index

    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction
08-21-2007, 01:30 AM#9
Dil999
Something ive been wondering for quiet a long time: Why did blizzard even include things as pointless as AttachSoundToUnitBJ or GetUnitStateSwapped? Do they have any real use other than taking up space?
08-21-2007, 04:15 AM#10
uberfoop
It's cuz of how the GUI orders parameters; they wanted parameters switched around so that they wouldn't need to switch them around during the compile process.

That doesn't change the fact that it's stupid though.