• 🏆 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!

New to JASS- can somebody please tell what is wrong in code

Status
Not open for further replies.
Level 2
Joined
Jul 13, 2005
Messages
21
I am trying to convert a corpse explosion ability I have written in GUI into JASS (only the functions are the same, otherwise the JASS was written from scratch). As usual 200 some compile errors. Since this is the first spell I have written I am completely lost as to what is causing them. (oh and yes i am using a custom model set in the mpq (feastaura)).



constant function Corpse_SpellId takes nothing returns integer
return 'A027' //Rawcode of Corpse Explosion Ability
endfunction

constant function Corpse_SFXMain takes nothing returns string
return "Spells\\Aura\\feastaura.mdx" //String name of warning SFX
endfunction

constant function Corpse_SFX takes nothing returns string
return "Objects\\Spawnmodels\\Demon\\DemonLargeDeathExplode\\DemonLargeDeathExplode.mdl"
//String name of explosion SFX
endfunction

constant function CorpseTarg_SFX takes nothing returns string
return "Objects\\Spawnmodels\\Demon\\DemonLargeDeathExplode\\DemonLargeDeathExplode.mdl"
//String name of target SFX
endfunction

constant function Corpse_DamCriteria takes player castown, unit f returns boolean
return (IsPlayerEnemy(GetOwningPlayer(f), castown)) and not(IsUnitType(f, UNIT_TYPE_MAGIC_IMMUNE)) and
not(IsUnitType(f, UNIT_TYPE_DEAD))
endfunction

constant function Corpse_Criteria takes unit p returns boolean
return (IsUnitType(p, UNIT_TYPE_DEAD)) and not(IsUnitType(p, UNIT_TYPE_HERO))
endfunction

constant function DamAmount takes unit f integer level returns integer
if not(IsUnitType(f, UNIT_TYPE_STRUCTURE)) then
return 45*level
else
return 45*level*0.30
endfunction

constant function CorpseSpell_Range takes integer level returns real
return 350+(level*0)//Level is not affecting range of effect
endfunction

constant function CorpseExpl_Range takes integer level returns real
return 200+(level*0)//Level is not affecting range of explosions
endfunction

constant function DamType takes nothing returns damagetype
return DAMAGE_TYPE_DISEASE
endfunction

constant function AttType takes nothing returns attacktype
return ATTACK_TYPE_CHAOS
endfunction

//=================================================================================
function CorpseExp_Conditions takes nothing returns boolean
return GetSpellAbilityId()==Corpse_SpellId()
endfunction

function groupunits takes location castloc, player castown, unit cast, integer level returns nothing
local group g=GetUnitsInRangeOfLocAll( CorpseSpell_Range(level), castloc)
local unit p=FirstOfGroup(g)
loop
exitwhen p==null
set p=FirstOfGroup(g)
call GroupRemoveUnit(g, p)
if (Corpse_Criteria(p)) then
call explodeunit(p, cast, castown, level)
endif
endloop
endfunction
//Gets all the corpses in the target area using the criteria in the header


function explodeunits takes unit p, unit cast, player castown, integer level returns nothing
local location loc=GetUnitLoc(p)
local group g=GetUnitsInRangeOfLocAll( CorpseExpl_Range(level), loc )
local unit f=FirstOfGroup(g)
local effect array sp
local integer n=0
local integer i=0
local effect sfx=AddSpecialEffectLoc(Corpse_SFX(), loc)
loop
exitwhen f==null
set f=FirstOfGroup(g)
call GroupRemoveUnit(g, f)
if (Corpse_DamCriteria(castown, f)) then
set loc=GetUnitLoc(f)
set sp[n]=AddSpecialEffectTarget(CorpseTarg_SFX(), f, "chest")
call damageunit(f, cast, level)
call RemoveUnit(p)
set n=n+1
endif
endloop
call TriggerSleepAction(.3) //Adjust time for special effect completion
loop
exitwhen i==n
call DestroyEffect(sp)
set i=i+1
endloop

call RemoveLocation(loc)
set n=0
set i=0
endfunction
//Creates the explosions at each corpse and damages units according to header criteria

function damageunit takes unit f, unit cast, integer level returns nothing
call UnitDamageTargetBJ(f, cast, DamAmount(f, level), AttType(), DamType())
endfunction

function CorpseExp_begin takes nothing returns nothing
local unit cast=GetSpellAbilityUnit()
local location castloc=GetSpellTargetLoc()
local player castown=GetOwningPlayer(cast)
local integer level=GetUnitAbilityLevel(cast, Corpse_SpellId())
local effect sp=AddSpecialEffectLoc(Corpse_SFXMain(), castloc)
call TriggerSleepAction(0.4)//Wait before explosions begin and removing warningeffect
call groupunits(castloc, castown, cast, level)
call DestroyEffect(sp)
endfunction

//====================================================================================

function InitTrig_Corpse_Explosion takes nothing returns nothing
set gg_trg_Corpse_Explosion = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Corpse_Explosion, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( gg_trg_Corpse_Explosion, Condition( function CorpseExp_Conditions ) )
call TriggerAddAction( gg_trg_Corpse_Explosion, function CorpseExp_begin )
endfunction
 
Level 7
Joined
May 6, 2005
Messages
390
JASS:
constant function Corpse_SpellId takes nothing returns integer
return 'A027' //Rawcode of Corpse Explosion Ability
endfunction

constant function Corpse_SFXMain takes nothing returns string
return "Spells\\Aura\\feastaura.mdx" //String name of warning SFX
endfunction

constant function Corpse_SFX takes nothing returns string
return "Objects\\Spawnmodels\\Demon\\DemonLargeDeathExplode\\DemonLargeDeathExplode.mdl"
//String name of explosion SFX
endfunction

constant function CorpseTarg_SFX takes nothing returns string
return "Objects\\Spawnmodels\\Demon\\DemonLargeDeathExplode\\DemonLargeDeathExplode.mdl"
//String name of target SFX
endfunction

constant function Corpse_DamCriteria takes player castown, unit f returns boolean
return (IsPlayerEnemy(GetOwningPlayer(f), castown)) and not(IsUnitType(f, UNIT_TYPE_MAGIC_IMMUNE)) and not(IsUnitType(f, UNIT_TYPE_DEAD))
endfunction

constant function Corpse_Criteria takes unit p returns boolean
return (IsUnitType(p, UNIT_TYPE_DEAD)) and not(IsUnitType(p, UNIT_TYPE_HERO))
endfunction

constant function DamAmount takes unit f, real level returns real
if not(IsUnitType(f, UNIT_TYPE_STRUCTURE)) then
return 45*level
endif
return 45*level*0.30
endfunction

constant function CorpseSpell_Range takes real level returns real
return 350+(level*0)//Level is not affecting range of effect
endfunction

constant function CorpseExpl_Range takes integer level returns real
return 200+(level*0)//Level is not affecting range of explosions
endfunction

constant function DamType takes nothing returns damagetype
return DAMAGE_TYPE_DISEASE
endfunction

constant function AttType takes nothing returns attacktype
return ATTACK_TYPE_CHAOS
endfunction

//=================================================================================
function CorpseExp_Conditions takes nothing returns boolean
return GetSpellAbilityId()==Corpse_SpellId()
endfunction

function groupunits takes location castloc, player castown, unit cast, integer level returns nothing
local group g=GetUnitsInRangeOfLocAll( CorpseSpell_Range(level), castloc)
local unit p=FirstOfGroup(g)
loop
exitwhen p==null
set p=FirstOfGroup(g)
call GroupRemoveUnit(g, p)
if (Corpse_Criteria(p)) then
call explodeunit(p, cast, castown, level)
endif
endloop
endfunction
//Gets all the corpses in the target area using the criteria in the header


function explodeunits takes unit p, unit cast, player castown, integer level returns nothing
local location loc=GetUnitLoc(p)
local group g=GetUnitsInRangeOfLocAll( CorpseExpl_Range(level), loc )
local unit f=FirstOfGroup(g)
local effect array sp
local integer n=0
local integer i=0
local effect sfx=AddSpecialEffectLoc(Corpse_SFX(), loc)
loop
exitwhen f==null
set f=FirstOfGroup(g)
call GroupRemoveUnit(g, f)
if (Corpse_DamCriteria(castown, f)) then
set loc=GetUnitLoc(f)
set sp[n]=AddSpecialEffectTarget(CorpseTarg_SFX(), f, "chest")
call damageunit(f, cast, level) // I expect this to be a cuctom function in your map? Else it's an error
call RemoveUnit(p)
set n=n+1
endif
endloop
call TriggerSleepAction(.3) //Adjust time for special effect completion
loop
exitwhen i==n
call DestroyEffect(sp[i])
set i=i+1
endloop

call RemoveLocation(loc)
set n=0
set i=0
endfunction
//Creates the explosions at each corpse and damages units according to header criteria

function damageunit takes unit f, unit cast, integer level returns nothing
call UnitDamageTargetBJ(f, cast, DamAmount(f, level), AttType(), DamType())
endfunction

function CorpseExp_begin takes nothing returns nothing
local unit cast=GetSpellAbilityUnit()
local location castloc=GetSpellTargetLoc()
local player castown=GetOwningPlayer(cast)
local integer level=GetUnitAbilityLevel(cast, Corpse_SpellId())
local effect sp=AddSpecialEffectLoc(Corpse_SFXMain(), castloc)
call TriggerSleepAction(0.4)//Wait before explosions begin and removing warningeffect
call groupunits(castloc, castown, cast, level)
call DestroyEffect(sp)
endfunction

//====================================================================================

function InitTrig_Corpse_Explosion takes nothing returns nothing
set gg_trg_Corpse_Explosion = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Corpse_Explosion, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( gg_trg_Corpse_Explosion, Condition( function CorpseExp_Conditions ) )
call TriggerAddAction( gg_trg_Corpse_Explosion, function CorpseExp_begin )
endfunction

This code should work, look at the comments I added, and if there's something you don't understand, ask me.
 
Level 2
Joined
Jul 13, 2005
Messages
21
Hi

Thanks for the reply.
I am probably just missing something but you said aside from the damageunit function the code should work? I have poured over it according to what I know and found no errors except for in the loop with removeunit(p) (cant do that more than once) Also I have the damageunit function in the code (a little further down from the comment.)

On the brighter side I reached a new record of 1940 compile errors.

But thanks for the comment. I have been having bad luck with JASS. Just cant ever seem to get it to work. I am wondering if this code needs to have some of the functions separated out or some other silliness.
 
Level 2
Joined
Jul 13, 2005
Messages
21
alright

I got what you were saying Blade. I just had to build code in W.E. to get it.

To reference a funciton it must be already created so

function x takes nothing returns nothing
endfunction

function y takes nothing returns nothing
call x()
endfunction

if function x was written below function y then y cannot call x.

Also when using a returns a real, all numbers aside from defined numbers must be in the form 0.00 so that the number is defined to two decimal places.

These were by far the major mistakes.

Thanks again
 
Status
Not open for further replies.
Top