• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Jass learning!

Status
Not open for further replies.
Level 5
Joined
Apr 12, 2009
Messages
125
Hi! I'm learning JASS and I'm wondering why i get this error....

JASS:
Line 98: Expected a function name

It says in JassCraft that there will be no problem, here's the code!

JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Cast_Forked takes unit caster, unit target returns nothing
    local unit dummy = CreateUnitAtLoc( GetOwningPlayer(caster), 'h001', GetUnitLoc(target), 270 )
    call UnitAddAbility( dummy, 'A001')
    call SetUnitAbilityLevel( dummy, 'A001', GetUnitAbilityLevel( caster, 'A000') )
    call IssueImmediateOrder( dummy, "fanofknives")
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Static_Charge takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function lol ) )
endfunction
 
Level 5
Joined
Apr 12, 2009
Messages
125
JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Cast_Forked takes unit caster, unit target returns nothing
    local unit dummy = CreateUnitAtLoc( GetOwningPlayer(caster), 'h001', GetUnitLoc(target), 270 )
    call UnitAddAbility( dummy, 'A001')
    call SetUnitAbilityLevel( dummy, 'A001', GetUnitAbilityLevel( caster, 'A000') )
    call IssueImmediateOrder( dummy, "fanofknives")
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Static_Charge takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function lol ) )
endfunction
//===========================================================================
function InitCustomTriggers takes nothing returns nothing
   call InitTrig_lol(  )          <-------------  That little thing, when i test the trigger, then this appear.... WTF
endfunction
 
Level 17
Joined
Sep 8, 2007
Messages
994
JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function Cast_Forked takes unit caster, unit target returns nothing
    local unit dummy = CreateUnitAtLoc( GetOwningPlayer(caster), 'h001', GetUnitLoc(target), 270 )
    call UnitAddAbility( dummy, 'A001')
    call SetUnitAbilityLevel( dummy, 'A001', GetUnitAbilityLevel( caster, 'A000') )
    call IssueImmediateOrder( dummy, "fanofknives")
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Static_Charge takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function lol ) )
endfunction
//===========================================================================
function InitCustomTriggers takes nothing returns nothing
   call InitTrig_lol(  )          <-------------  That little thing, when i test the trigger, then this appear.... WTF
endfunction

What the heck are you doing? :eek: ... oh wait a sec, you're learning it...
Ok, here's the problem. You try to call the initialization trigger, there is no need to do that. The initialization trigger "is called as first in the whole trigger automatically", it is kinda a "preparation" for the trigger itself. The initialization trigger can be identified by the "InitTrig_" prefix. To make it short and remove your bugs - remove this part:
JASS:
function InitCustomTriggers takes nothing returns nothing
   call InitTrig_lol(  )          <-------------  That little thing, when i test the trigger, then this appear.... WTF
endfunction

Another bug...
and btw, you did not add an action to the trigger. I suggest you do it, otherwise the spell will run nothing.
JASS:
function InitTrig_Static_Charge takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) // <-- You are adding an event to the trigger
    call TriggerAddCondition( t, Condition( function lol ) ) // <-- You are adding a condition to the trigger
//You are NOT adding an action to the trigger! Now, have a guess what you have to do!
endfunction
 
Level 5
Joined
Apr 12, 2009
Messages
125
I get this part under me!

What the heck are you doing? :eek: ... oh wait a sec, you're learning it...
Ok, here's the problem. You try to call the initialization trigger, there is no need to do that. The initialization trigger "is called as first in the whole trigger automatically", it is kinda a "preparation" for the trigger itself. The initialization trigger can be identified by the "InitTrig_" prefix. To make it short and remove your bugs - remove this part:

JASS:
function InitCustomTriggers takes nothing returns nothing
   call InitTrig_lol(  )          <-------------  That little thing, when i test the trigger, then this appear.... WTF
endfunction

This under me gets me confused...

Another bug...
and btw, you did not add an action to the trigger. I suggest you do it, otherwise the spell will run nothing.
JASS:
function InitTrig_Static_Charge takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) // <-- You are adding an event to the trigger
    call TriggerAddCondition( t, Condition( function lol ) ) // <-- You are adding a condition to the trigger
//You are NOT adding an action to the trigger! Now, have a guess what you have to do!
endfunction

Well, I think you understand my trigger I WANT to do. Can you make me one so I can learn from it?

/r0bfish
 
Level 17
Joined
Sep 8, 2007
Messages
994
I get this part under me!



This under me gets me confused...



Well, I think you understand my trigger I WANT to do. Can you make me one so I can learn from it?

/r0bfish

I'll just make the trigger ... I will care leaks and alike as well so that you learn how to kill/avoid leaks.

JASS:
//===========================================================================
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction
//===========================================================================
//This is the function which will be runned when the event has occured.
//Therefore, it takes nothing and returns nothing, obvious, isn't it?
function Cast_Forked takes nothing returns nothing
    //Ok, you obviously want to create a dummy unit at the target units position casting Fan of Knives.
    //This is how you should do it ...
    //First you have to get to the position of the target unit. With the function GetUnitLoc we can access the units position,
    //but you surely have heared of it - locations, unit groups, special effects (etc.) cause leaks if you don't treat them correctly.
    //So, what we now have to do is to create a location variable and give it the location of the target unit:
    local location TargetLoc = GetUnitLoc(GetSpellTargetUnit()) //If you want to access the target unit use: GetSpellTargetUnit()
    //Now we have the target location. Now just use the variable we just declared.
    // ( GetTriggerUnit() is the caster )
    local unit dummy = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h001', TargetLoc, 270)
    call UnitAddAbility( dummy, 'A001')
    call SetUnitAbilityLevel(dummy, 'A001', GetUnitAbilityLevel(GetTriggerUnit(), 'A000'))
    call IssueImmediateOrder(dummy, "fanofknives")
    //You just forgot to remove the dummy unit afterwards. Just add an expiration timer to it (makes the unit disappear after a certain time)
    //This is the function:
    call UnitApplyTimedLife(dummy, 'BTLK', 0.5) //This will make the dummy disappear after 0.5 seconds.
    
    //Ok, now we did everything we had to to. Now we have to remove the location's leak!
    //Do it like this:
    call RemoveLocation(TargetLoc) //The location is now removed, the leak reduced.
    //In order to remove the leak completely you have to nullify the variable (like you have to do with each local handle)
    set TargetLoc = null //nulled.
    set dummy = null //GJ, you nulled a local handle by yourself.
endfunction
//===========================================================================
function InitTrig_Static_Charge takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function lol))
    call TriggerAddAction(tri, function Cast_Forked) //Here, you have to add the action to the trigger, else nothing can happen...
endfunction
 
Level 5
Joined
Apr 12, 2009
Messages
125
I'll just make the trigger ... I will care leaks and alike as well so that you learn how to kill/avoid leaks.

JASS:
//===========================================================================
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction
//===========================================================================
//This is the function which will be runned when the event has occured.
//Therefore, it takes nothing and returns nothing, obvious, isn't it?
function Cast_Forked takes nothing returns nothing
    //Ok, you obviously want to create a dummy unit at the target units position casting Fan of Knives.
    //This is how you should do it ...
    //First you have to get to the position of the target unit. With the function GetUnitLoc we can access the units position,
    //but you surely have heared of it - locations, unit groups, special effects (etc.) cause leaks if you don't treat them correctly.
    //So, what we now have to do is to create a location variable and give it the location of the target unit:
    local location TargetLoc = GetUnitLoc(GetSpellTargetUnit()) //If you want to access the target unit use: GetSpellTargetUnit()
    //Now we have the target location. Now just use the variable we just declared.
    // ( GetTriggerUnit() is the caster )
    local unit dummy = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h001', TargetLoc, 270)
    call UnitAddAbility( dummy, 'A001')
    call SetUnitAbilityLevel(dummy, 'A001', GetUnitAbilityLevel(GetTriggerUnit(), 'A000'))
    call IssueImmediateOrder(dummy, "fanofknives")
    //You just forgot to remove the dummy unit afterwards. Just add an expiration timer to it (makes the unit disappear after a certain time)
    //This is the function:
    call UnitApplyTimedLife(dummy, 'BTLK', 0.5) //This will make the dummy disappear after 0.5 seconds.
    
    //Ok, now we did everything we had to to. Now we have to remove the location's leak!
    //Do it like this:
    call RemoveLocation(TargetLoc) //The location is now removed, the leak reduced.
    //In order to remove the leak completely you have to nullify the variable (like you have to do with each local handle)
    set TargetLoc = null //nulled.
    set dummy = null //GJ, you nulled a local handle by yourself.
endfunction
//===========================================================================
function InitTrig_Static_Charge takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function lol))
    call TriggerAddAction(tri, function Cast_Forked) //Here, you have to add the action to the trigger, else nothing can happen...
endfunction

No, you dont.
Did you rename the trigger in the trigger editor after converting it to custom text?
If yes, you need to change the InitTrig_Static_Charge function's name to InitTrig_lol.
Or, you move on to vJass and dont bother with that kind of dependencies, youll understand them soon enough.






WOOW :D Thank all +rep to ya'll :D

And btw, I know what leaks is. Jass is new to me, but not GUI ;)

But i think i'll get it ^^
 
Level 5
Joined
Apr 12, 2009
Messages
125
Well, this is what I've come up to. I saw a mistake

JASS:
function lol takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction
//===========================================================================

function fanofknives takes nothing returns nothing
    local location TargetLoc = GetUnitLoc(GetSpellTargetUnit())
    local unit dummy = CreateUnitAtLoc(GetOwningPlayer(GetTriggerUnit()), 'h000', TargetLoc, 270)  // What does 270 means? :S
    call UnitAddAbility( dummy, 'A001')
    call SetUnitAbilityLevel(dummy, 'A001', GetUnitAbilityLevel(GetTriggerUnit(), 'A000'))
    call IssueImmediateOrder(dummy, "thunderclap")
    call UnitApplyTimedLife(dummy, 'BTLK', 0.5)

    call RemoveLocation(TargetLoc)
    set TargetLoc = null
    set dummy = null
endfunction
//===========================================================================
function InitTrig_lol takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function lol))
    call TriggerAddAction(t, function fanofknives) // Instead of TriggerAddAction(t,   it was like  TriggerAddAction(tri   :)
endfunction

But for my question, thunderclap's special effects won't show ingame. Only the stun(pause) over target unit will show. How do I add special effects? :p
 
Level 17
Joined
Sep 8, 2007
Messages
994
// What does 270 means? :S
It is the angle the unit faces. 270 is the default.
// Instead of TriggerAddAction(t, it was like TriggerAddAction(tri :)
Ye, I got used to use "tri" as the name for the trigger <.<
How do I add special effects?
Depends what kind of special effect you're up to. You can use these:
JASS:
function AddSpecialEffect takes string modelName, real X, real y returns effect
function AddSpecialEffectLoc takes string modelName, location loc returns effect
function AddSpecialEffectTarget takes string modelName, widget target, string AttachementRegion returns effect
//Before you ask, widget basically is every unit, destructable and other objects which "can die ingame"
//Please note that effects are leaks as well. Here's the function to remove these:
function DestroyEffect takes effect SPX returns nothing
 
Level 5
Joined
Apr 12, 2009
Messages
125
It is the angle the unit faces. 270 is the default.
Ye, I got used to use "tri" as the name for the trigger <.<
Depends what kind of special effect you're up to. You can use these:
JASS:
function AddSpecialEffect takes string modelName, real X, real y returns effect
function AddSpecialEffectLoc takes string modelName, location loc returns effect
function AddSpecialEffectTarget takes string modelName, widget target, string AttachementRegion returns effect
//Before you ask, widget basically is every unit, destructable and other objects which "can die ingame"
//Please note that effects are leaks as well. Here's the function to remove these:
function DestroyEffect takes effect SPX returns nothing

Well, I don't actually understand how to put these actions in the trigger.
Should I create a new function or what?

How should the trigger look alike if you would do it? :p

And what do they mean by "string modelName"?
 
Level 5
Joined
Apr 12, 2009
Messages
125
The modelName is the effect path. Use GUI, then convert it to JASS, to find the effect path. To use, simply do:
JASS:
call DestroyEffect(AddSpecialEffectLoc(modelName, TargetLoc))
The DestroyEffect as soon as it's created means it will play its birth animation then disappear, which is perfect for what you want.

Yeah, that seems good.

But what should I write in "modelName" ?
 
Level 12
Joined
May 21, 2009
Messages
994
But isn't BJ's bad?

yes i think its because its slower than non-bj's..
in some cases their is non-bjs functions like urs its
JASS:
call AddSpecialEffectLoc(modelpath, thelocation)
and
JASS:
call AddSpecialEffectLocBJ(thelocation, modelpath)

you see the difference? in the non-bj its modelpath first and location after
in the bj its the location first and the modelpath after..

But in some functions you cant remove the BJ then their will only exist a BJ function..
 
Level 5
Joined
Apr 12, 2009
Messages
125
yes i think its because its slower than non-bj's..
in some cases their is non-bjs functions like urs its
JASS:
call AddSpecialEffectLoc(modelpath, thelocation)
and
JASS:
call AddSpecialEffectLocBJ(thelocation, modelpath)

you see the difference? in the non-bj its modelpath first and location after
in the bj its the location first and the modelpath after..

But in some functions you cant remove the BJ then their will only exist a BJ function..

woho! More thx, +rep to you ^^
 
Status
Not open for further replies.
Top