My first spell In JASS need help

adeoin

Member
Reaction score
11
So my jass trigger came up with alot of syntax errors and i got the feeling i did something very wrong. I'm done yet but i just wanna get it checked before i continue. Tell me anything wrong with it

JASS:
function Trig_JASS_Lightning_Ba_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
endfunction
set u = GetSpellAbilityUnit
set p = GetUnitLoc(GetSpellTargetUnit)
set r = GetUnitFacing(u)
call CreateUnitAtLoc( h000 , 1, p, r)
call QueueUnitAnimation ( GetLastCreatedUnit , Attack)

//===========================================================================
function InitTrig_JASS_Lightning_Ba takes nothing returns nothing
    set gg_trg_JASS_Lightning_Ba = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Lightning_Ba, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_JASS_Lightning_Ba, Condition( function Trig_Lightning_Ball_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_JASS_Lightning_Ba, function Trig_Lightning_Ball_Copy_Actions )
endfunction
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
WARNING: I'm bad at explaining

First, put ur functions inside, since your stuffs are in outside hehe,
look
JASS:
function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
endfunction  <<MOVE THIS DOWN
set u = GetSpellAbilityUnit //They are not inside
set p = GetUnitLoc(GetSpellTargetUnit)
set r = GetUnitFacing(u)
call CreateUnitAtLoc( h000 , 1, p, r)
call QueueUnitAnimation ( GetLastCreatedUnit , Attack)
endfunction <<IN HERE

RESULT
JASS:
function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
set u = GetSpellAbilityUnit //They are now inside <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />
set p = GetUnitLoc(GetSpellTargetUnit)
set r = GetUnitFacing(u)
call CreateUnitAtLoc( h000 , 1, p, r)
call QueueUnitAnimation ( GetLastCreatedUnit , Attack)
endfunction &lt;&lt;IN HERE


Before you set u, p, and r, you must first declare them by typing

JASS:
local(TYPE)(NAME)

local unit u
local location l
local real r


But, you can just put their values there as initial values. example

local unit u = GetSpellAbilityUnit()
local location l = GetUnitLoc(u)
local real r = GetUnitFacing(u)

And when using a function that requires nothing, you should not remove the part with "()". Even though they require nothing doesn't mean you should remove that. It's just like [ljass]CreateUnitAtLoc[/ljass] so:

CreateUnitAtLoc requires: PLAYER, RAWCODE, LOCATION, FACING
CreateUnitAtLoc(Player(0),?,?,?)
Player 0 is player 1,
player numbers are decreased by 1 in jass.
but use [ljass]GetOwningPlayer[/ljass] which requires a unit, this will tell the player that owns the unit, so if we
CreateUnitAtLoc(GetOwningPlayer(u),?,?,?) That means the unit will be created for the owner of u. nxt

the rawcode stuff, when a rawcode is required on a function, you will need to add this , [ljass]''[/ljass] so they will be identified as rawcode. example
[ljass]CreateUnitAtLoc(GetOwningPlayer(u),'h000',?,?)[/ljass]

Notice that you didn't use '' at your trigger(you only type h000. should be 'h000'), and will be added as a reason on your error. nxt

Locations, yeah, since you have declared the location, use the l variable u declared
[ljass]CreateUnitAtLoc(GetOwningPlayer(u),'h000',l,?)[/ljass]

Now the facing, just same....

[ljass]CreateUnitAtLoc(GetOwningPlayer(u),'h000',l,r)[/ljass]

=============================

[ljass]call QueueUnitAnimation ( GetLastCreatedUnit , Attack)[/ljass]
You should remove bj's, since they are the makers of lag.
GetLastCreatedUnit's native is [ljass]bj_lastCreatedUnit[/ljass] but this is a constant, and you will learn more about them. Result

[ljass]call QueueUnitAnimation ( bj_lastCreatedUnit , Attack)[/ljass]

the second one, the animation, since it requires a string, you need to use a quotation mark. Put a quotation mark at start and end. like "Attack" so they will be indentified as strings. Result

[ljass]call QueueUnitAnimation ( bj_lastCreatedUnit , "Attack")[/ljass]

==================================

Now, setting them null and removing them to prevent leaks which causes map lags.

by typing [ljass]RemoveLocation(LOCATION)[/ljass]
This will remove the location variable, to prevent leaks
[ljass]RemoveLocation(l)[/ljass]

set them null
type
[ljass]set u = null
set l = null[/ljass]

leakless

I will not teach you how to fix this
JASS:
function Trig_JASS_Lightning_Ba_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == &#039;A000&#039; ) ) then
        return false
    endif
    return true
endfunction

and 

function InitTrig_JASS_Lightning_Ba takes nothing returns nothing
    set gg_trg_JASS_Lightning_Ba = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Lightning_Ba, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_JASS_Lightning_Ba, Condition( function Trig_Lightning_Ball_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_JASS_Lightning_Ba, function Trig_Lightning_Ball_Copy_Actions )
endfunction

since I am bad at explaining. Other guys will teach you.

Final:

JASS:
function Trig_JASS_Lightning_Ba_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == &#039;A000&#039; ) ) then
        return false
    endif
    return true
endfunction

function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
endfunction
local unit u = GetSpellAbilityUnit()
local location l = GetUnitLoc(u)
local real r = GetUnitFacing(u)
call CreateUnitAtLoc(GetOwningPlayer(u),&#039;h000&#039;,l,r)
call QueueUnitAnimation ( bj_lastCreatedUnit, &quot;Attack&quot;)

//===========================================================================
function InitTrig_JASS_Lightning_Ba takes nothing returns nothing
    set gg_trg_JASS_Lightning_Ba = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Lightning_Ba, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_JASS_Lightning_Ba, Condition( function Trig_Lightning_Ball_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_JASS_Lightning_Ba, function Trig_Lightning_Ball_Copy_Actions )
endfunction


If you have learned the basics of vjass gracefully, your trigger will turn to:

JASS:
scope Lightning initializer I
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == &#039;A000&#039;
    endfunction

    private function Actions takes nothing returns nothing
        local unit u = GetSpellAbilityUnit()
        local location l = GetUnitLoc(u)
        local real r = GetUnitFacing(u)

        call CreateUnitAtLoc(GetOwningPlayer(u),&#039;h000&#039;,l,r)
        call QueueUnitAnimation ( bj_lastCreatedUnit, &quot;Attack&quot;)
        call RemoveLocation(l)

        set u = null
        set l = null
    endfunction

    //===========================================================================
    private function I takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_CAST)
        call TriggerAddCondition(t,Condition(function Conditions))
        call TriggerAddAction(t,function Actions)
    endfunction
endscope


and when you learn vjass MORE and MORE. you will get:

JASS:
scope Lightning initializer I
    globals
        private constant integer RAWCODE   = &#039;A000&#039;   //The Rawcode of spell
        private constant integer DUMMY     = &#039;h000&#039;   //The Rawcode of dummy

        private constant string  ANIMATION = &quot;attack&quot; //The animation played on dummy

        private constant real    DURATION  = 1.       //The Dummy Duration
    endglobals

    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == RAWCODE
    endfunction

    private function Actions takes nothing returns nothing
        local unit d
        local unit u = GetSpellAbilityUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real r = GetUnitFacing(u)

        set d = CreateUnit(GetOwningPlayer(u),DUMMY,x,y,r)

        call SetUnitAnimation(d,ANIMATION)
        call UnitApplyTimedLife(d,&#039;BTLF&#039;,1.)

        set u = null
        set d = null
    endfunction

    //===========================================================================
    private function I takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            call TriggerRegisterPlayerUnitEvent(t,Player(i),EVENT_PLAYER_UNIT_SPELL_CAST,null)

            set i = i+1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddCondition(t,Condition(function Conditions))
        call TriggerAddAction(t,function Actions)
    endfunction
endscope


End by da wey, you should check this out.

and also check this

REMEMBER:
string = ""
rawcode = ''
Nothing = ()
local, their type and name
Use "TAB" button for the awesome spaces(for what? To read and understand your trigger easier)
spaces doesn't matter, like [ljass]CreateUnitAtLoc( Player( 6 ) , 'h001' , loc , faaaaaaaccccccceeeee )[/ljass]
 

Laiev

Hey Listen!!
Reaction score
188
@Nherwyziant
I like your 'bad explain' (you said it lol)

just a thing, you don't need to remove the BJ trigger event.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

JASS:
function Trig_JASS_Lightning_Ba_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == &#039;A000&#039; ) ) then
        return false
    endif
    return true
endfunction


can be

JASS:
function Trig_JASS_Lightning_Ba_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == &#039;A000&#039;
endfunction


JASS:
function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
endfunction
set u = GetSpellAbilityUnit
set p = GetUnitLoc(GetSpellTargetUnit)
set r = GetUnitFacing(u)
call CreateUnitAtLoc( h000 , 1, p, r)
call QueueUnitAnimation ( GetLastCreatedUnit , Attack)


fixing the bugs and fails may be

JASS:
function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
    local unit u        = GetTriggerUnit()
    local unit dummy
    local unit targ     = GetSpellTargetUnit()
    local location p    = GetUnitLoc(targ)
    local real r        = GetUnitFacing(u)

    set dummy = CreateUnitAtLoc(GetOwningPlayer(u), &#039;h000&#039; , p, r)
    call QueueUnitAnimation (dummy, &quot;Attack&quot;)

    call RemoveLocation (p)
    set p          = null
    set u          = null
    set dummy      = null
    set targ       = null
endfunction


I don't remember right, but i'm right, [ljass]CreateUnitAtLoc[/ljass] don't set [ljass]bj_lastCreatedUnit[/ljass] so you NEED [ljass]set variable = CreateUnit...~[/ljass]
 

adeoin

Member
Reaction score
11
thanks guys really helped :] another question.... how do you do waits in JASS?
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, the actual native is [ljass]TriggerSleepAction( real )[/ljass]...
But, I'd suggest you use a timer for all of your waits, as that native isn't very accurate, but timers are ;)
 

jig7c

Stop reading me...-statement
Reaction score
123
just make a Wait action in GUI, and the convert it to JASS

its something like

call TriggerSleepAction (5) // 5 second wait...

edit: komaqtion beat me to it!
 

adeoin

Member
Reaction score
11
few more questions... srry :p

1. How do i set a 'local' after the beggining. Because after the locals are set my trigger creates a unit, how can i set that unit as last created unit.

2. How do you run another trigger in JASS
 

jig7c

Stop reading me...-statement
Reaction score
123
1.
JASS:
function Example takes nothing returns nothing
 local unit u = GetTriggeringUnit()
 local location l = GetLoc (u)
 local player p
 set p = GetTriggeringPlayer ()  //use set variablename = some native once the locals are declared up top!
 call ......
 call ....
 call ....
 call RemoveLocation (l)
 set u = null
endfunction


2. Make a GUI trigger, with the action line:
Trigger:
  • Run Example2 &lt;gen&gt; ignoring/checking conditions

then convert it to custom text and see what happens!
i think it's call TriggerQueue (trigger name)
 

Kenny

Back for now.
Reaction score
202
JASS:
function InitTrig_JASS_Lightning_Ba takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( trig, Condition(function trig ) ) // &lt;----
    call TriggerAddAction( trig, function trig ) // &lt;----
endfunction


Those should be something like this:

JASS:
function InitTrig_JASS_Lightning_Ba takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( trig, Condition(function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction


As those are the functions that will run when the event is executed.

The variable trig was just the trigger you are attaching the conditions and actions to, not the actual functions themselves.

After the keyword [ljass]function[/ljass] in both of those lines, you should put the name of you condition and action functions.

In your first post they are called something like:

Trig_Lightning_Ball_Copy_Conditions
Trig_Lightning_Ball_Copy_Actions
 

adeoin

Member
Reaction score
11
thanks :D

yeah another question.... How come it comes up with an error for this trigger... the error is

Undeclared Variable Trig_Move_Lightnign
Undeclared Variable gg_trg_Move_Lightnign

JASS:
function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local unit lcu
    local trigger turnon = (Trig_Move_Lighnign)
    local location cp = GetUnitLoc(u)
    local unit ut = GetSpellTargetUnit()
    local location l = GetUnitLoc(ut)
    local real r = GetUnitFacing(u)
    call CreateUnitAtLoc(GetOwningPlayer(u) , &#039;h000&#039;, cp, r)
    set lcu = GetLastCreatedUnit()
    set turnon = ( gg_trg_Move_Lightnign )
    call QueueUnitAnimation ( u , &quot;Attack&quot;)
    call TriggerSleepAction(3.0)
    call EnableTrigger( turnon )
endfunction
//===========================================================================
function InitTrig_JASS_Lightning_Ba takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( trig, Condition(function Trig_JASS_Lightning_Ba_Conditions ) )
    call TriggerAddAction( trig, function Trig_JASS_Lightning_Ba_Actions) 
endfunction
 

Nherwyziant

Be better than you were yesterday :D
Reaction score
96
thanks :D

yeah another question.... How come it comes up with an error for this trigger... the error is

Undeclared Variable Trig_Move_Lightnign
Undeclared Variable gg_trg_Move_Lightnign

JASS:
function Trig_JASS_Lightning_Ba_Actions takes nothing returns nothing
    local unit u = GetSpellAbilityUnit()
    local unit lcu
    local trigger turnon = (Trig_Move_Lighnign)
    local location cp = GetUnitLoc(u)
    local unit ut = GetSpellTargetUnit()
    local location l = GetUnitLoc(ut)
    local real r = GetUnitFacing(u)
    call CreateUnitAtLoc(GetOwningPlayer(u) , &#039;h000&#039;, cp, r)
    set lcu = GetLastCreatedUnit()
    set turnon = ( gg_trg_Move_Lightnign )
    call QueueUnitAnimation ( u , &quot;Attack&quot;)
    call TriggerSleepAction(3.0)
    call EnableTrigger( turnon )
endfunction
//===========================================================================
function InitTrig_JASS_Lightning_Ba takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( trig, Condition(function Trig_JASS_Lightning_Ba_Conditions ) )
    call TriggerAddAction( trig, function Trig_JASS_Lightning_Ba_Actions) 
endfunction


Because [ljass]call TriggerAddCondition( trig, Condition(function Trig_JASS_Lightning_Ba_Conditions ) )[/ljass] needs the function Trig_JASS_Lightning_Ba_Conditions which doesn't exist on your trigger.

Add this at the top of your trigger or somewhere else above your initializer

JASS:
function Trig_JASS_Lightning_Ba_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == &#039;A000&#039;
endfunction
 

Laiev

Hey Listen!!
Reaction score
188
the second error is because variable [ljass]gg_trg_Move_Lightnign[/ljass] don't exist :rolleyes:

need see what is to fix it :p
 
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