| 08-19-2007, 04:54 PM | #1 |
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 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 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 |
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: 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 |
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: 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: 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 |
Add JASS:u = null -Av3n |
| 08-20-2007, 08:43 AM | #5 |
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 |
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 |
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 Code:
function SinBJ takes real degrees returns real
return Sin(degrees * bj_DEGTORAD)
endfunctionBJ'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 |
In addition, many BJ's are absolutely pointless: JASS:function AttachSoundToUnitBJ takes sound soundHandle, unit whichUnit returns nothing call AttachSoundToUnit(soundHandle, whichUnit) endfunction And some are somewhat useful: 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 |
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 |
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. |
