• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Local variables

Status
Not open for further replies.
Level 7
Joined
Dec 18, 2008
Messages
400
Hello
I've a trigger i made in GUI and converted it to JASS, because i wanted to have local variable and make i MUI, but i have some problem with the code :cry:

Here's the part of my code that i cant get to work with local variables:
JASS:
    set udg_Oo_Terrain = GetTerrainTypeBJ(GetRectCenter(RectFromCenterSizeBJ(Location(udg_Oo_pX, udg_Oo_pY), udg_Oo_Area, udg_Oo_Area))) 
    
    set udg_Oo_Lvl = I2R(GetUnitAbilityLevelSwapped(GetSpellAbilityId(), udg_Oo_Caster))
    
    set udg_Oo_Area = ( 100.00 * udg_Oo_Lvl )
    
    set udg_Oo_Copy_str = I2R(GetHeroStatBJ(bj_HEROSTAT_STR, udg_Oo_Caster, true))
    
    set udg_Oo_effect = GetLastCreatedEffectBJ()

My problem is that i dont know what the code statement is called, could someone help me out :)

Btw how can i add wait time (say i want to wait 5 and the destroy last created special effect) if i want this to be MUI?
 
JASS:
local unit caster = GetTriggerUnit()
 
local integer terrain = GetTerrainType(0.,0.) 
 
local integer level = GetUnitAbilityLevel(caster, GetSpellAbilityId())
 
local real area = 100. *level
 
local real strength = I2R(GetHeroStr(caster, true))
 
local effect sfx = AddSpecialEffectTarget("",caster,"origin")
call TriggerSleepAction(5.00)
call DestroyEffect(sfx)
 
Level 7
Joined
Dec 18, 2008
Messages
400
JASS:
local integer level = GetUnitAbilityLevel(caster, GetSpellAbilityId()) 
local real strength = I2R(GetHeroStr(caster, true))

The editor doesn't seems to like this :cry:

EDIT:
It doesnt work when i copy it into my trigger, but when i just copy it into an empty trigger it works.

EDIT2:
None of them works in my trígger
 
You have to put the local values at the very top of the function.

JASS:
function SomeName takes nothing returns nothing
    local integer something
    //Actions
endfunction
 
// Is not the same as:
 
function SomeName takes nothing returns nothing
    //Actions
    local integer something
endfunction

The second one gives you syntax errors (which is what you're doing).
 
Level 7
Joined
Dec 18, 2008
Messages
400
this is how i tried to set up my trigger
JASS:
 function Trig_Plauge_Touch_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Plauge_Touch_Actions takes nothing returns nothing
    local unit PT_Caster = GetSpellAbilityUnit()
    local unit PT_Target = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(caster, GetSpellAbilityId())
endfunction

//===========================================================================
function InitTrig_Plauge_Touch takes nothing returns nothing
    set gg_trg_Plauge_Touch = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Plauge_Touch, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Plauge_Touch, Condition( function Trig_Plauge_Touch_Conditions ) )
    call TriggerAddAction( gg_trg_Plauge_Touch, function Trig_Plauge_Touch_Actions )
endfunction
Still gives me an error
 
Level 9
Joined
Aug 21, 2008
Messages
533
JASS:
 local unit PT_Caster = GetSpellAbilityUnit()
    local unit PT_Target = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(caster, GetSpellAbilityId())

should be

JASS:
 local unit PT_Caster = GetSpellAbilityUnit()
    local unit PT_Target = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(PT_Caster, GetSpellAbilityId())

casue there is no caster variable, only a PT_Caster one
 
Level 7
Joined
Dec 18, 2008
Messages
400
I guess you're right, but as you've probally guessed i'm new to jass ^^

BTW i encountered another problem :cry:
When i copy this into JASS and tries to save my map, it suddenly stops responding.

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

function Trig_testing_Copy_Func010Func001Func001C takes nothing returns boolean
    if ( not ( IsUnitEnemy(GetEnumUnit(), GetOwningPlayer(PT_Caster)) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_testing_Copy_Func010Func001A takes nothing returns nothing
    if ( Trig_testing_Copy_Func010Func001Func001C() ) then
        call AddSpecialEffectTargetUnitBJ( "origin", GetEnumUnit(), "Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl" )
        local effect PT_Effect = AddSpecialEffectTarget("",PT_Target,"origin")
        call UnitDamageTargetBJ( PT_Caster, GetEnumUnit(), PT_INT, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
        call DestroyEffectBJ( PT_Effect )
    else
    endif
endfunction

function Trig_testing_Copy_Func010C takes nothing returns boolean
    if ( not ( GetUnitStateSwap(UNIT_STATE_LIFE, PT_Target) < 1.00 ) ) then
        return false
    endif
    return true
endfunction

function Trig_testing_Copy_Actions takes nothing returns nothing
    local unit PT_Caster = GetSpellAbilityUnit()
    local unit PT_Target = GetSpellTargetUnit()
    local real PT_LVL = I2R(GetUnitAbilityLevelSwapped(GetSpellAbilityId(), PT_Caster))
    local real PT_Area = ( PT_LVL * 150.00 )
    local real PT_INT = I2R(GetHeroStatBJ(bj_HEROSTAT_INT, PT_Caster, true))
    local real PT_Target_X = GetLocationX(GetUnitLoc(PT_Target))
    local real PT_Target_Y = GetLocationY(GetUnitLoc(PT_Target))
    if ( Trig_testing_Copy_Func010C() ) then
        call ForGroupBJ( GetUnitsInRangeOfLocAll(PT_Area, Location(PT_Target_X, PT_Target_Y)), function Trig_testing_Copy_Func010Func001A )
    else
    endif
endfunction

//===========================================================================
function InitTrig_testing_Copy takes nothing returns nothing
    set gg_trg_testing_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_testing_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_testing_Copy, Condition( function Trig_testing_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_testing_Copy, function Trig_testing_Copy_Actions )
endfunction
 
JASS:
function testing_Copy_Group_Enum takes nothing returns boolean
    local unit filt = GetFilterUnit()
    if IsUnitEnemy(filt,bj_groupEnumOwningPlayer) then
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl",filt,"origin"))
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl",filt,"origin"))
        call UnitDamageTarget(bj_lastLoadedUnit,filt, bj_meleeNearestMineDist,true,false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )
    endif
    set filt = null
    return false
endfunction
 
function Trig_testing_Copy_Actions takes unit caster,unit target returns nothing
    set bj_meleeNearestMineDist = I2R(GetHeroInt(caster,true))
    set bj_groupEnumOwningPlayer = GetTriggerPlayer()
    set bj_lastLoadedUnit = caster
    if GetWidgetLife(target) < 1 then
        call GroupEnumUnitsInRange(bj_lastCreatedGroup,GetUnitX(target),GetUnitY(target),150. * GetUnitAbilityLevel(caster,GetSpellAbilityId()),Filter(function testing_Copy_Group_Enum))
    endif
endfunction
 
function Trig_testing_Copy_Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'A000' then
        call Trig_testing_Copy_Actions(GetTriggerUnit(),GetSpellTargetUnit())
    endif
    return false
endfunction
 
//===========================================================================
function InitTrig_testing_Copy takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_testing_Copy_Conditions ) )
endfunction
 
His script is an optimized version of yours. It groups the units within a 150*spellLevel range of the caster, and damages the enemy grouped units for damage equal to the caster's intellect. Then it creates two effects on each enemy.

It uses blizzard's default globals, but the bj_lastCreatedGroup method might not work so well. You should just replace that with an empty group variable because in most cases it will return null, or it will conflict with some GUI grouping.

JASS:
function testing_Copy_Group_Enum takes nothing returns boolean
//this is the filtering (conditions) of the units being enumerated 
    local unit filt = GetFilterUnit() //gets the unit being filtered
    if IsUnitEnemy(filt,bj_groupEnumOwningPlayer) then
//makes sure that the unit being filtered is an enemy of the caster
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl",filt,"origin")) //creates an effect
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl",filt,"origin")) //creates an effect
        call UnitDamageTarget(bj_lastLoadedUnit,filt, bj_meleeNearestMineDist,true,false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )
//damages the unit for the intelligence 
    endif
    set filt = null
//nulls the local variable
    return false
//returns false since it is a filter function
endfunction
 
function Trig_testing_Copy_Actions takes unit caster,unit target returns nothing
    set bj_meleeNearestMineDist = GetHeroInt(caster,true) //stores the hero's intelligence
    set bj_groupEnumOwningPlayer = GetTriggerPlayer() //stores the owner of the casting hero
    set bj_lastLoadedUnit = caster //stores the caster
    if GetWidgetLife(target) > 0.405 then //I'm pretty sure you want to check if the target is alive
        call GroupEnumUnitsInRange(udg_MyGroupVariable,GetUnitX(target),GetUnitY(target),150. * GetUnitAbilityLevel(caster,GetSpellAbilityId()),Filter(function testing_Copy_Group_Enum)) 
//Groups the surrounding units within 150*casterSpellLevel
    endif
endfunction
 
function Trig_testing_Copy_Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'A000' then //checks if the rawcode of the spell being cast is equal to 'A000' (your spell)
        call Trig_testing_Copy_Actions(GetTriggerUnit(),GetSpellTargetUnit())
        //calls the action function
    endif
    return false //returns false (or true) since it must return a boolean as it is a condition
endfunction
 
//===========================================================================
function InitTrig_testing_Copy takes nothing returns nothing //map initialization function
    local trigger t = CreateTrigger() //creates the trigger
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) //registers when a unit starts the effect of an ability
    call TriggerAddCondition( t, Condition( function Trig_testing_Copy_Conditions ) ) //adds the condition for the trigger
endfunction
 
Level 7
Joined
Dec 18, 2008
Messages
400
Thanks a lot :thumbs_up:

EDIT:
actually its supposed to damage the spell target, if it dies, the caster will damage everyone within 150*ability lvl
btw is your spell mui?
 
EDIT:
actually its supposed to damage the spell target, if it dies, the caster will damage everyone within 150*ability lvl
btw is your spell mui?

Okay:
JASS:
function testing_Copy_Group_Enum takes nothing returns boolean
//this is the filtering (conditions) of the units being enumerated
    local unit filt = GetFilterUnit() //gets the unit being filtered
    if IsUnitEnemy(filt,bj_groupEnumOwningPlayer) and GetWidgetLife(filt)>0.405 then
//makes sure that the unit being filtered is an enemy of the caster
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl",filt,"origin")) //creates an effect
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl",filt,"origin")) //creates an effect
        call UnitDamageTarget(bj_lastLoadedUnit,filt, bj_meleeNearestMineDist,true,false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )
//damages the unit for the intelligence
    endif
    set filt = null
//nulls the local variable
    return false
//returns false since it is a filter function
endfunction
 
function Trig_testing_Copy_Actions takes unit caster,unit target returns nothing
    set bj_meleeNearestMineDist = GetHeroInt(caster,true) //stores the hero's intelligence
    set bj_groupEnumOwningPlayer = GetTriggerPlayer() //stores the owner of the casting hero
    set bj_lastLoadedUnit = caster //stores the caster
    call UnitDamageTarget(caster,target,bj_meleeNearestMineDist,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS) //damages the target
    if GetWidgetLife(target) < 0.405 then
        call GroupEnumUnitsInRange(udg_MyGroupVariable,GetUnitX(target),GetUnitY(target),150. * GetUnitAbilityLevel(caster,GetSpellAbilityId()),Filter(function testing_Copy_Group_Enum)) 
//Groups the surrounding units within 150*casterSpellLevel
    endif
endfunction
 
function Trig_testing_Copy_Conditions takes nothing returns boolean
    if GetSpellAbilityId() == 'A000' then //checks if the rawcode of the spell being cast is equal to 'A000' (your spell)
        call Trig_testing_Copy_Actions(GetTriggerUnit(),GetSpellTargetUnit())
        //calls the action function
    endif
    return false //returns false (or true) since it must return a boolean as it is a condition
endfunction
 
//===========================================================================
function InitTrig_testing_Copy takes nothing returns nothing //map initialization function
    local trigger t = CreateTrigger() //creates the trigger
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT ) //registers when a unit starts the effect of an ability
    call TriggerAddCondition( t, Condition( function Trig_testing_Copy_Conditions ) ) //adds the condition for the trigger
endfunction
 
There are restrictions by using a global variable instead of a local, however, when you learn to stop using TriggerSleepAction, global variables are almost always preferred because of how easy it is to use Group Enumeration and other quick grabs. When you get really good in JASS, you'll be using arrays like crazy, because they are wonderful.
 
When you get really good in JASS, you'll be using arrays like crazy, because they are wonderful.
To follow through on this earlier statement, it should have been a billboard indicator that I was referring to the array component of structs.
You talked about array, and Table > Array.
So you'd prefer vexorian uses hashtable instead of arrays for the JASSHelper struct compilation? Either my English isn't crossing over very well to you, or you're not putting the pieces together.
 
Structs are actually like classes.

A class can have an member, f.e. teatime

JASS:
struct tea
    private string teatime = "4pm"
endstruct

So vexorian saves this as
JASS:
    string array tea_teatime[ISTANCE_MAXIMUM]

if you do this
JASS:
local tea t = tea.create()
set t.teatime = "5pm"

then vexorians JASS does this:
JASS:
set tea_teatime[t] = "5pm"

So actually, a struct instance is an index pointer of all of those arrays.
Struct surely themself can have arrays, then one array is assoziated to more as one struct instance.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You mean an "unlimited" index? That's hardly much to worry about. Not only that but thanks to vJass you can actually use arrays with limits greater than 8190, so there isn't much of a problem here. The only thing that Table does for you is use the hashtable functions. If you know how to use them properly, then there isn't much use for table at all.
 
Status
Not open for further replies.
Top