• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Help with script

Status
Not open for further replies.
Level 8
Joined
Dec 29, 2006
Messages
359
When i go to save my map or test it, I cant because I get errors like 'expected ('
or 'expected variable name' This is in this particular code

JASS:
function Trig_Enigma_Conditions takes nothing returns boolean
    UnitHasBuffBJ( GetAttackedUnitBJ, B000 )
    return true
endfunction

function Trig_Enigma_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit au = GetAttacker()
    local integer i = GetRandomInt( 1, 20 )
    if i == 1 then
        local real ux = GetUnitX( u )
        local real uy = GetUnitY( u )
        local integer p = DecUnitAbilityLevel( u, 'A000' )
        local real d = DecUnitAbilityLevel( u, 'A000' * 15 )
        local real r = DecUnitAbilityLevel( u, 'A000' * 100 )
        loop
            exitwhen p == 0
            call PolledWait( 0.50 )
            call AddSpecialEffect( Abilities\Spells\Human\Thunderclap\ThunderClapCaster.mdl, ux, uy )
            call DestroyEffect( GetLastCreatedEffectBJ )
            call UnitDamagePoint( u, 0.00, r, ux, uy, d, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_AXE_MEDIUM_CHOP )
            set p = p - 1
            if p == 0 then
                set p = DecUnitAbilityLevel( u, 'A000' )
            
            endif
            
        endloop
   
    endif
    
    if i == 2 then
        local real d = DecUnitAbilityLevel( u, 'A000' * 25 )
        local real aux = GetUnitX( au )
        local real auy = GetUnitY( au )
        call AddSpecialEffect( Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl, aux, auy )
        call DestroyEffect( GetLastCreatedEffectBJ )
        call UnitDamageTarget( u, au, d, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_MEDIUM_BASH )
    
    endif
    
    if i = 3 then
        local location locu = GetUnitLoc( u )
        local location locau = GetUnitLoc( au )
        local real ang = AngleBetweenPoints( loca, locau )
        local real d = DecUnitAbilityLevel( u, 'A000' * 19 )
        local integer p = DecUnitAbilityLevel( u, 'A000' * 6 )
        loop
            exitwhen p == 0
            call PolledWait( 0.15 )
            call AddSpecialEffectLoc( Abilities\Spells\Undead\FrostNova\FrostNovaTarget.mdl, locu )
            call DestroyEffect( GetLastCreatedEffectBJ )
            call UnitDamageTarget( u, au, d, true, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_METAL_HEAVY_BASH )
            set locu = PolarProjectionBJ( locu, 10.00, ang )
            if p == 0 then
                set p = DecUnitAbilityLevel( u, 'A000' * 6 )
            
            endif
        
        endloop
    
    endif
    
endfunction

//==== Init Trigger Enigma ====
function InitTrig_Enigma takes nothing returns nothing
    set gg_trg_Enigma = CreateTrigger()
    //call TriggerRegister__(gg_trg_Enigma, )
    call TriggerRegisterAnyUnitEventBJ(, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_Enigma, Condition(function Trig_Enigma_Conditions))
    call TriggerAddAction(gg_trg_Enigma, function Trig_Enigma_Actions)
endfunction

It makes it so whoever has the spell learned will have a 3 in 20 chance of retaliating with either a thunderclap, individual damage spell, or a beam. Can someone tell me what im doing wrong? Or better yet just how to locate and fix these problems?
Thanks to all replies.
 
Last edited by a moderator:
Level 3
Joined
May 1, 2007
Messages
29
JASS:
UnitHasBuffBJ( GetAttackedUnitBJ, B000 )
    return true

should be


JASS:
return UnitHasBuffBJ( GetAttackedUnitBJ, B000 )
 
Last edited by a moderator:
Level 11
Joined
Jul 12, 2005
Messages
764
Problems with the condition:
-a condition does not look like that
-uses UnitHasBuffBJ
-uses GetAttackedUnitBJ

Actually it should be:
JASS:
function Trig_Enigma_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), 'B000') > 0
endfunction
 
Last edited by a moderator:
Level 8
Joined
Dec 29, 2006
Messages
359
Well I fixed the condition, but I still get a lot of errors saving or testing the map: Lines 36-40---Expected 'endif' Line 42, 44---Expected a name. Just to name a few. How can I fix these errors?
 
Level 8
Joined
Dec 29, 2006
Messages
359
Well, I re-typed the entire code... Of course since I'm still working in JASS its still got a few errors I'm having trouble with.

New Code:

JASS:
function Trig_Enigma_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), 'B000') > 0
endfunction

function Trig_Enigma_Actions takes nothing returns nothing
    local unit cu = GetTriggerUnit()
    local unit au = GetAttacker()
    local integer i = GetRandomInt(1, 10)
    local integer i1 = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
    local location culoc = GetUnitLoc(cu)
    local location auloc = GetUnitLoc(au)
    local real ang = AngleBetweenPoints(culoc, auloc)
    local real dam = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
        if i == 1 then
        loop
            exitwhen i1 == 0
            call PolledWait(0.50)
            call AddSpecialEffectLoc(Abilities\Spells\Human\Thunderclap\ThunderClapCaster.mdl, culoc)
            call DestroyEffect(GetLastCreatedEffectBJ)
            call UnitDamagePointLoc(cu, 0.00, dam * 50.00, culoc, dam * 15.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
            if i1 == 0 then
                set i1 = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
            elseif i1 => 0 then
                set i1 = i1 - 1
            endif
            
        endloop
     
    elseif i == 2 then
        call AddSpecialEffectLoc(Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl, auloc)
        call DestroyEffect(GetLastCreatedEffectBJ)
        call UnitDamagePointLoc(cu, 0.00, 10.00, auloc, dam * 30, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)
    
    elseif i == 3 then  
        set i1 = i1 * 5
        loop
            exitwhen i1 == 0
            call PolledWait(0.10
            call PolarProjectionBJ(culoc, dam * 10, ang)
            call AddSpecialEffectLoc(Abilities\Spells\Undead\FrostNova\FrostNovaTarget.mdl, culoc)
            call DestroyEffect(GetLastCreatedEffectBJ)
            call UnitDamagePointLoc(cu, 0.00, dam * 15, culoc, dam * 20, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL)
            if i1 == then
                set i1 = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
                set i1 = i1 * 5
            elseif i1 => then
                set i1 = i1 - 1
                
            endif
            
            
        endloop
        
        
    
    endif

endfunction



//==== Init Trigger Enigma ====
function InitTrig_Enigma takes nothing returns nothing
    set gg_trg_Enigma = CreateTrigger()
    //call TriggerRegister__(gg_trg_Enigma, )
    call TriggerRegisterAnyUnitEventBJ(, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_Enigma, Condition(function Trig_Enigma_Conditions))
    call TriggerAddAction(gg_trg_Enigma, function Trig_Enigma_Actions)
endfunction

For some reason though...I get an error when testing the map that says 'expected endif' but the problem is, the line that its saying has an error, does have endif in it. Whats wrong? Thanks for the help so far everyone :D
 
Last edited by a moderator:
Level 40
Joined
Dec 14, 2005
Messages
10,532
JASS:
function Trig_Enigma_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), 'B000') > 0
endfunction

function Trig_Enigma_Actions takes nothing returns nothing
    local unit cu = GetTriggerUnit()
    local unit au = GetAttacker()
    local integer i = GetRandomInt(1, 10)
    local integer i1 = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
    local location culoc = GetUnitLoc(cu)
    local location auloc = GetUnitLoc(au)
    local real ang = AngleBetweenPoints(culoc, auloc)
    local real dam = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
        if i == 1 then
        loop
            exitwhen i1 == 0
            call PolledWait(.5)
            call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl", culoc))
            call UnitDamagePointLoc(cu, 0, dam * 50, culoc, dam * 15, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL)
            if i1 == 0 then
                set i1 = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
            elseif i1 >= 0 then
                set i1 = i1 - 1
            endif
            
        endloop
    
    elseif i == 2 then
        call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl", auloc))
        call UnitDamagePointLoc(cu, 0, 10, auloc, dam * 30, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)
    
    elseif i == 3 then  
        set i1 = i1 * 5
        loop
            exitwhen i1 == 0
            call PolledWait(0.10)
            call PolarProjectionBJ(culoc, dam * 10, ang)
            call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", culoc))
            call UnitDamagePointLoc(cu, 0, dam * 15, culoc, dam * 20, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL)
            if i1 == 0 then
                set i1 = GetUnitAbilityLevel(GetTriggerUnit(), 'A000')
                set i1 = i1 * 5
            elseif i1 >= 0 then
                set i1 = i1 - 1
                
            endif
            
            
        endloop
        
        
    
    endif

endfunction



//==== Init Trigger Enigma ====
function InitTrig_Enigma takes nothing returns nothing
    set gg_trg_Enigma = CreateTrigger()
    //call TriggerRegister__(gg_trg_Enigma, )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Enigma, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(gg_trg_Enigma, Condition(function Trig_Enigma_Conditions))
    call TriggerAddAction(gg_trg_Enigma, function Trig_Enigma_Actions)
endfunction

There's a working version of what you posted. It still, however, leaves much to be desired in code improvements.

What was wrong with your code --

-">" has priority over "=", so it's ">=" or "<=", not "=>" or "=<"

-you forgot a number in the second if-statement (and elseif) ("if i1 == then")

-GetLastCreatedEffectBJ needs () after it -- it's a function

-You forgot closing brackets in a few places

-Strings must be enclosed in "". \ in a string should be \\ except for in special situations

-you forgot the trigger parameter of TriggerRegisterAnyUnitEventBJ

Other critiques:

-Locations suck
-Leaks
-AddSpecialEffectLoc() doesn't set bj_lastCreatedEffect
-PolarProjectionBJ returns a value. You need to set var = PolarProjectionBJ...

I suggest using a parser such as JassCraft to find these errors. The WE parser sucks.
 
Level 8
Joined
Dec 29, 2006
Messages
359
I fixed the leaks

Code:
    set cu = null
    set au = null
    set i = null
    set i1 = null
    set culoc = null
    set auloc = null
    set ang = null
    set dam = null
endfunction

please tell me one thing though (keeping in mind that this is all under one function (Trig_Enigma_Actions)) Why is it that when I go to null these locals, do I get the undeclared variable (cu)
undeclared variable (au)
etc. Errors?
One more thing. When I use the syntax checker in Jasscraft, what do I fix when I get a syntax error?
 
Level 8
Joined
Dec 29, 2006
Messages
359
Thanks Diablo-dk, that helps a bunch. Now can anyone explain what a syntax error is? Thats the most prominent error i keep getting with the jasscraft syntax checker.
 
Level 3
Joined
Aug 19, 2005
Messages
47
Syntax error is almost everything Jasscraft (or any other processor) cannot understand, so it usually is when you have broken parentheses, qotes or you just forgot some very important key word.
 
Level 3
Joined
May 1, 2007
Messages
29
Well....To define Syntax i am gonna use english languge. When you misspell or use periods or commas or anything like that in the english languge its considered bad "syntax" (btw i have horrible syntax with english 0.0), it's sorta like grammer rules. With humans we are ussually able to decifier the bad syntax and still make sence of it.

But computers are not that smart so if you don't follow the programming languge rules, or syntax, the computer goes "WTF are you trying to say?????" And then tells you where in your code it can't read. You look at that location in your code and figure out what is typed incorrectly. Also ALWAYS, atleast this is my rule of thumb, rerun the syntax checker after you fix a syntax error cause that syntax error can cause a domino effect for the syntax checker that causes the sytax checker to say your code has alot more errors then it truly does. I could go into a more advanced way of using the syntax errors and other errors to figure out what is wrong with your code if you wish me to. =)
 
Level 3
Joined
May 1, 2007
Messages
29
Just a few simple rules.

1. 90% of the time the line that the syntax checker tells you the problem is on is one above the line that accually has the problem.

2. If the syntax checker tells you "expected name" it is most likely because you misspelled a variable. It almost always has to do with this issues. BUT if thats not the issue one other very common reason is you did not put the () on the end of a function call and thus thinks your function call is really a undecleared(undefined) variable.

3. This is the more tricky rule, and this is what you eventully have to go to if the other rules of thumb don't find the issue. It is possible that somewhere ABOVE the line that says there is a problem lies the accual problem. This can occur when you do some sort of statment that technicly does not violate syntax, BUT because it is incorrect screws up the flow of your code latter on. This one is really hard to be specific on, and is really the hardest part of Syntax debugging(by far not the hardest of all types of debugging, syntax debugging means getting your code so it compiles, not nesserly so it does what you want it to do, thats always the toughest part, lol).

4. Almost always rerun the syntax checker after you have fixed a problem as one problem can have a domino effect on the syntax of the rest of your code.

5. When writing code space it out nicely, its worth it. Makes it sooooo much easier to read and find problems. Also always name variables in a smart way when possible.
 
Status
Not open for further replies.
Top