HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

My Trigger/jass questions

10-26-2006, 12:52 AM#1
Joker
Gonna post all my questions here so that i dont make a lot of threads

1. Can someone tell me what leaks? All I know is that the Unit Group leaks and if you dont null a local or not destroy an effect.

2. Is there a way to use loops (in Jass of course) to shorted down triggers that uses diff fuctions for diff lvls.

Example for 2.
Trigger:
Dwindle
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Dwindle
Collapse Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Dwindle for (Casting unit)) Equal to 1
Collapse Then - Actions
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True)) and do (Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 100.00))
Unit - Set life of (Casting unit) to ((Life of (Casting unit)) + ((Real((Number of units in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))))) x 100.00))
Special Effect - Create a special effect attached to the overhead of (Casting unit) using Abilities\Spells\Items\AIta\CrystalBallCaster.mdl
Special Effect - Create a special effect attached to the chest of (Targeted unit) using Abilities\Spells\Undead\Cripple\CrippleTarget.mdl
Special Effect - Destroy (Last created special effect)
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Dwindle for (Casting unit)) Equal to 2
Collapse Then - Actions
Special Effect - Destroy (Last created special effect)
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True)) and do (Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 175.00))
Unit - Set life of (Casting unit) to ((Life of (Casting unit)) + ((Real((Number of units in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))))) x 175.00))
Special Effect - Create a special effect attached to the overhead of (Casting unit) using Abilities\Spells\Items\AIta\CrystalBallCaster.mdl
Special Effect - Destroy (Last created special effect)
Special Effect - Create a special effect attached to the chest of (Targeted unit) using Abilities\Spells\Undead\Cripple\CrippleTarget.mdl
Special Effect - Destroy (Last created special effect)
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Dwindle for (Casting unit)) Equal to 3
Collapse Then - Actions
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True)) and do (Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 250.00))
Unit - Set life of (Casting unit) to ((Life of (Casting unit)) + ((Real((Number of units in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))))) x 250.00))
Special Effect - Create a special effect attached to the overhead of (Casting unit) using Abilities\Spells\Items\AIta\CrystalBallCaster.mdl
Special Effect - Destroy (Last created special effect)
Special Effect - Create a special effect attached to the chest of (Targeted unit) using Abilities\Spells\Undead\Cripple\CrippleTarget.mdl
Special Effect - Destroy (Last created special effect)
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Dwindle for (Casting unit)) Equal to 4
Collapse Then - Actions
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True)) and do (Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 325.00))
Unit - Set life of (Casting unit) to ((Life of (Casting unit)) + ((Real((Number of units in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))))) x 325.00))
Special Effect - Create a special effect attached to the overhead of (Casting unit) using Abilities\Spells\Items\AIta\CrystalBallCaster.mdl
Special Effect - Destroy (Last created special effect)
Special Effect - Create a special effect attached to the chest of (Targeted unit) using Abilities\Spells\Undead\Cripple\CrippleTarget.mdl
Special Effect - Destroy (Last created special effect)
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Level of Dwindle for (Casting unit)) Equal to 5
Collapse Then - Actions
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True)) and do (Unit - Set life of (Picked unit) to ((Life of (Picked unit)) - 400.00))
Unit - Set life of (Casting unit) to ((Life of (Casting unit)) + ((Real((Number of units in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))))) x 400.00))
Special Effect - Create a special effect attached to the overhead of (Casting unit) using Abilities\Spells\Items\AIta\CrystalBallCaster.mdl
Special Effect - Destroy (Last created special effect)
Special Effect - Create a special effect attached to the chest of (Targeted unit) using Abilities\Spells\Undead\Cripple\CrippleTarget.mdl
Special Effect - Destroy (Last created special effect)
Else - Actions

3.
I set the unit of targets to 1, but it shoots out 2 missiles.... whats wrong?

more questions posted later

p.s. Love these Orc smileys :)
10-26-2006, 01:45 AM#2
Archmage Owenalacaster
I'll answer your first question... kind of:
Quote:
Originally Posted by The)TideHunter(
I'll explain the basis of leakage.
A handle is something that isn't a string, real, integer, boolean or code.
A handle leaks, if it's not a handle, don't worry about it.
A string supposedly leaks once, although I wouldn't call this a leak, more of a optimization for reusage.
Anyway, you only have to destroy a handle, and you only have to set a handle to null.
10-26-2006, 02:54 AM#3
zen87
1st question will be something like above
2nd question : well of course, jass always looks more neat when it comes to big loop compared to GUI
3rd question : well i think that's barrage ability, no matter what you set, the minimum ammount of missle shoot out is always 3, even you change the number lower it won't do, but you do can reduce the damage shoot out by combine barrage and destroy tower from thinker (dota's medusa way of solving this problem)
10-26-2006, 09:57 AM#4
The)TideHunter(
Quote:
Originally Posted by Archmage Owenalacaster
I'll answer your first question... kind of:

Thanks for pointing me out =).

Anyway, to add onto what he quoted me, heres the post:
http://wc3campaigns.net/showpost.php...9&postcount=10
10-26-2006, 09:05 PM#5
aidan_124
Answer to 2nd question i think:
Collapse JASS:
// if ability level for unit
local integer i = GetUnitAbilityLevel(unit)
// if level of hero then
local integer i = GetHeroLevel(hero)
if i = 1 then
    call function A
elseif i = 2 then
    call function B
elseif i = 3 then
    call function C

//etc.
endif

endfunction
I'm new(ish) to JASS but i think you can stack elseif s like that.
Fairly sure that programming an array of functions (if you can) would take you longer than above.
10-26-2006, 09:17 PM#6
Captain Griffen
Quote:
Anyway, you only have to destroy a handle, and you only have to set a handle to null.

NO! Totally, totally wrong.

Object Leaks:

Objects take up memory. Some objects (eg: units) automatically clear themselves up once they go out of scope. Others, such as locations, do not.

As such, whenever you create groups, forces, locations, etc., then you should catch them in a variable, and destroy them later, using functions such as RemoveLocation, DestroyGroup, DestroyForce, etc..

Handle Index Leaks:

Handles indexes do not automatically decrement if a variable goes out of scope, only when they are set to something else. This is only really significant for local variables, as globals cannot go out of scope, and so thus are much less of an issue.

If the count on a handle index is not decremented, then the index will be permamently counted as taken up, and thus take hostage some memory until the end of the game. As such, unless the variable is pointing to a permament object, you should set local variables of handle type to null at the end of a function. This is not needed if the value has been passed to the function, rather than set within the function itself.


These are two radically different types of leak, of which the first is normally the most potent.
10-26-2006, 09:42 PM#7
The)TideHunter(
Quote:
Originally Posted by Captain Griffen
NO! Totally, totally wrong.

Object Leaks:

Objects take up memory. Some objects (eg: units) automatically clear themselves up once they go out of scope. Others, such as locations, do not.

As such, whenever you create groups, forces, locations, etc., then you should catch them in a variable, and destroy them later, using functions such as RemoveLocation, DestroyGroup, DestroyForce, etc..

I dont agree.
A unit can still have to be removed, take a dummy for instance, if you dont remove that, it will always be there, a unit is no exception to any other handle, although the main causes might be group and location, a unit still has a possability to needed to be removed.
10-26-2006, 09:48 PM#8
Captain Griffen
Dummy units don't go out of scope now, do they? When a unit decays (which dummy units, presumably with locust, don't) then they clean up the object memory automatically. Killing a dummy unit would, it decays, have the same effect as removing it.

Units have a garbage collector, locations don't (fortunately).
10-26-2006, 09:58 PM#9
Vexorian
Units don't have a garbage collector...

Units simply get removed automatically if dead + decay.

Then their handle gets replaced by a dummy handle or something like that

and that is removed once references == 0
10-26-2006, 11:08 PM#10
Joker
ty everyone for helping me out.

4. Is there really a difference between Unit-Remove Unit and Unit -Kill Unit? if yes, then are there different situations when you use them?

5. Why are BJ things so bad? how would you replace them? like GetAttackedUnitBJ, what would you replace that with?
10-26-2006, 11:19 PM#11
The)TideHunter(
4:

Remove unit instantly removes the unit from the game, kill unit lets it decay, plays its death sound etc. Like setting a units hp to 0.

5:

BJ's are just functions blizzard made for multiple reasons, some known, some unkown.

But lets take KillSoundWhenDoneBJ for example, lets look what it does:

Collapse JASS:
function KillSoundWhenDoneBJ takes sound soundHandle returns nothing
    call KillSoundWhenDone(soundHandle)
endfunction

All it does is uses the function call KillSoundWhenDone(soundHandle), but the problem is, why should we do that, when we can just use that function in the first place, its a waste of computing time. It is completly pointless when you can just write call KillSoundWhenDone(soundHandle) and save computing time

Some BJ's are good, if you want your code to be neater, such as OrderId2StringBJ, i wouldent really want:

Collapse JASS:
function OrderId2StringBJ takes integer orderId returns string
    local string orderString

    // Check to see if it's a generic order.
    set orderString = OrderId2String(orderId)
    if (orderString != null) then
        return orderString
    endif

    // Check to see if it's a (train) unit order.
    set orderString = UnitId2String(orderId)
    if (orderString != null) then
        return orderString
    endif

    // Unrecognized - return an empty string.
    return ""
endfunction

Sticking out in the middle of my code, so sometimes it helps.
But TBH, i would reccomend not using them, every single BJ is possible to write itself, 75% of the time they are just wrapper function like my first example which do nothing.
Aviod them!
Nearly all GUI functions, when converted to Jass, are BJ's, when you clean your map up, convert all your triggers to Jass, and simply remove all the useless BJ's, your map will be alot more professional and cleaner.
10-27-2006, 12:16 AM#12
Joker
6. How do i change BJ's into non-BJ's ? Im having some trouble doing so

7. help me fix this...this is creating 92 compiled errors in my map...
Collapse JASS:
function Trig_Drop_Bomb_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A03O'
endfunction

function Trig_Drop_Bomb_UnitType takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'e004' )
endfunction

function Trig_Drop_Bomb_GiveTimer takes nothing returns nothing
    call UnitApplyTimedLifeBJ( 120.00, 'BTLF', GetEnumUnit() )
endfunction


function Trig_Drop_Bomb_Actions takes nothing returns nothing
    local unit BombCaster = GetSpellAbilityUnit()
    local integer BombLvl  = GetUnitAbilityLevel( BombCaster, 'A03O')
    local integer NumBomb = 0
    if BombLvl == 1 then
        loop
            call CreateNUnitsAtLocFacingLocBJ( 1, 'e004', GetOwningPlayer(BombCaster), GetRandomLocInRect(GetPlayableMapRect()), GetUnitLoc(GetTriggerUnit()) )
            set NumBomb = NumBomb + 1
            exitwhen NumBomb == 20
        endloop
    set bj_wantDestroyGroup = true
    call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Drop_Bomb_UnitType)), function Trig_Drop_Bomb_GiveTimer )
    set NumBomb = 0
    elseif BombLvl == 2 then
        loop
            call CreateNUnitsAtLocFacingLocBJ( 1, 'e004', GetOwningPlayer(BombCaster), GetRandomLocInRect(GetPlayableMapRect()), GetUnitLoc(GetTriggerUnit()) )
            set NumBomb = NumBomb + 1
            exitwhen NumBomb == 30
        endloop
    set bj_wantDestroyGroup = true
    call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Drop_Bomb_UnitType)), function Trig_Drop_Bomb_GiveTimer )
    set NumBomb = 0
    elseif BombLvl == 3 then
        loop
            call CreateNUnitsAtLocFacingLocBJ( 1, 'e004', GetOwningPlayer(BombCaster), GetRandomLocInRect(GetPlayableMapRect()), GetUnitLoc(GetTriggerUnit()) )
            set NumBomb = NumBomb + 1
            exitwhen NumBomb == 45
        endloop
    set bj_wantDestroyGroup = true
    call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Drop_Bomb_UnitType)), function Trig_Drop_Bomb_GiveTimer )
    set NumBomb = 0
    endif
    set BombCaster = null
endfunction

//===========================================================================
function InitTrig_Drop_Bomb takes nothing returns nothing
    set gg_trg_Drop_Bomb = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Drop_Bomb, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Drop_Bomb, Condition( function Trig_Drop_Bomb_Conditions ) )
    call TriggerAddAction( gg_trg_Drop_Bomb, function Trig_Drop_Bomb_Actions )
endfunction
10-27-2006, 05:32 AM#13
zen87
6. Well try search around and get JassCraft, it has all the native list and you can see what are all those BJ-s are made off and replace them with the most fundemental natives (again, save computing time)
7. Hmmm where your error started ?
10-27-2006, 10:38 AM#14
The)TideHunter(
Yes, as Zen said, get Jasscraft, whenever i look up any function or its BJ i always just open it.

The reason why you sometimes get errors is because BJ's normally switch the order of parameters, lets take your ApplyTimedLife
The BJ:
function UnitApplyTimedLifeBJ takes real duration, integer buffId, unit whichUnit returns nothing
And the native:
native UnitApplyTimedLife takes unit whichUnit, integer buffId, real duration returns nothing
Notice the difference.
Anyways, theyre was no errors in your code, it parsed fine.
10-27-2006, 06:40 PM#15
Joker
Quote:
Originally Posted by zen87
7. Hmmm where your error started ?
yes, it says its fine of jasscraft, but it creates 92 compiled errors on the map...is there something thats causing that?