jass function

dansam92

New Member
Reaction score
1
i coded my own out of combat sys.
37936446.jpg

this is outline of my triggers.

this is a function includeded in out of combat trigger.
26264989.jpg

the function works well and there is no prob.

but
when i use the function in another trigger(brush check) like below,
91692478.jpg

map crashed.

wht can i do?
can't i use a function in one trigger in another trigger?
 

Komaqtion

You can change this now in User CP.
Reaction score
469
can't i use a function in one trigger in another trigger?

No...
You need to move that function into the "Map Header" (The thing at the top of the triggers-list, with the map's name on it ;)) then just call it in both the other triggers ;)
 

PurgeandFire

zxcvmkgdfg
Reaction score
508
No...
You need to move that function into the "Map Header" (The thing at the top of the triggers-list, with the map's name on it ;)) then just call it in both the other triggers ;)

Well, not necessarily. =P As long as one trigger is above the other, its functions can be called by the trigger below. (As long as they aren't private) =)

Anyway, is it only when you add that function? If you are testing it online, this might cause a desync:
JASS:
function brush_check_f takes nothing returns boolean
    local unit cast = udg_brush_unit
    local unit tar = GetFilterUnit()
    local string p = ""
    local effect eff
    if GetUnitDistance(cast,tar) <= 300. and IsUnitType(tar,UNIT_TYPE_STRUCTURE) != true then
        if GetUnitAbilityLevel(cast,'Agho') > 0 then
            if GetLocalPlayer() != GetOwningPlayer(cast) then
                set p = "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl"
            endif
        endif


It causes the string table to be unsynced if that was used for the first time:
JASS:
    local string p = "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl" 
//Change it to this


Change the local player block to this:
JASS:
            if GetLocalPlayer() != GetOwningPlayer(cast) then
    set p = ""
endif
//change it to this as well


Also, does the function work fine normally? (Without crashing) Does it crash if you set some other unit in combat other than "cast"?

Btw, you can post your codes in [noparse]
JASS:
[/noparse] tags, since it makes it easier for us to edit your code.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
> can't i use a function in one trigger in another trigger?

Use a library. :p
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Use scope and libraries for your codes.

Here's a template:
Trigger 1 (convert to custom text, then paste this)
JASS:

library MyFunctions initializer Init

    globals
        // globals go here, if only used inside library, make 'em private
    endglobals

    private function PrivateFunctionality takes nothing returns nothing
        // Only used by this library
    endfunction

    function PubliclyUsableFunction takes nothing returns nothing
        // Publicly available
        // Example: IsUnitInCombat takes unit u returns boolean
    endfunction


    // ==================================================
    // Initalizer
    private function Init takes nothing returns nothing
        // Initialize some globals/triggers/units/etc... here
    endfunction
endlibrary


Trigger 2 (convert to custom text, then paste this)
JASS:

library SomeSpell initializer Init requires MyFunctions
    // Spell stuff here

    // ==================================================
    // Initalizer
    private function Init takes nothing returns nothing
        // Initialize some globals/triggers/units/etc... here
    endfunction
endlibrary
 

dansam92

New Member
Reaction score
1
whereas now im using JNGP, my jass helper is not working...
so i cnt use library or scope...

PurgeandFire//
i tested before, it was fine. (no desync)
but i should change into what u said for a safety. :)
thx for ur advice.
next time, i will post my code with
JASS:
.

i change the trigger into local trigger, then i can call one trigger's functions in another.
here is my code to check combat status. there is any leaks or something else i should edit?
<div class="bbCodeBlock bbCodeBlock--screenLimited bbCodeBlock--code"><div class="bbCodeBlock-title">JASS:</div><div class="bbCodeBlock-content"><pre class="bbCodeCode"><code class="jass"><span class="keyword">function</span> <span>GetUnitCombatState</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>u</span> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/boolean" class="type">boolean</a>
    <span class="keyword">return</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/LoadTimerHandle" class="native">LoadTimerHandle</a><span class="symbol">(</span><span>udg_hash</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>u</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/StringHash" class="native">StringHash</a><span class="symbol">(</span>&<span>quot</span>;<span>ooc_t</span>&<span>quot</span>;<span class="symbol">)</span><span class="symbol">)</span><span class="symbol">=</span><span class="symbol">=</span><span class="value">null</span>
<span class="keyword">endfunction</span>

<span class="keyword">function</span> <span>EndCombat</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/timer" class="type">timer</a> <span>t</span><span class="symbol">=</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetExpiredTimer" class="native">GetExpiredTimer</a><span class="symbol">(</span><span class="symbol">)</span>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>u</span><span class="symbol">=</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/LoadUnitHandle" class="native">LoadUnitHandle</a><span class="symbol">(</span><span>udg_hash</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>t</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/StringHash" class="native">StringHash</a><span class="symbol">(</span>&<span>quot</span>;<span>ooc_u</span>&<span>quot</span>;<span class="symbol">)</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/FlushChildHashtable" class="native">FlushChildHashtable</a><span class="symbol">(</span><span>udg_hash</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>u</span><span class="symbol">)</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/FlushChildHashtable" class="native">FlushChildHashtable</a><span class="symbol">(</span><span>udg_hash</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>t</span><span class="symbol">)</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/PauseTimer" class="native">PauseTimer</a><span class="symbol">(</span><span>t</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/DestroyTimer" class="native">DestroyTimer</a><span class="symbol">(</span><span>t</span><span class="symbol">)</span>
    <span class="keyword">set</span> <span>t</span><span class="symbol">=</span><span class="value">null</span>
<span class="keyword">endfunction</span>

<span class="keyword">function</span> <span>SetUnitInCombat</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>u</span> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/timer" class="type">timer</a> <span>t</span><span class="symbol">=</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/LoadTimerHandle" class="native">LoadTimerHandle</a><span class="symbol">(</span><span>udg_hash</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>u</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/StringHash" class="native">StringHash</a><span class="symbol">(</span>&<span>quot</span>;<span>ooc_t</span>&<span>quot</span>;<span class="symbol">)</span><span class="symbol">)</span>
    <span class="keyword">if</span> <span>t</span><span class="symbol">=</span><span class="symbol">=</span><span class="value">null</span> <span class="keyword">then</span>
        <span class="keyword">set</span> <span>t</span><span class="symbol">=</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/CreateTimer" class="native">CreateTimer</a><span class="symbol">(</span><span class="symbol">)</span>
        <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/SaveTimerHandle" class="native">SaveTimerHandle</a><span class="symbol">(</span><span>udg_hash</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>u</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/StringHash" class="native">StringHash</a><span class="symbol">(</span>&<span>quot</span>;<span>ooc_t</span>&<span>quot</span>;<span class="symbol">)</span><span class="symbol">,</span><span>t</span><span class="symbol">)</span>
    <span class="keyword">endif</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/SaveUnitHandle" class="native">SaveUnitHandle</a><span class="symbol">(</span><span>udg_hash</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetHandleId" class="native">GetHandleId</a><span class="symbol">(</span><span>t</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/StringHash" class="native">StringHash</a><span class="symbol">(</span>&<span>quot</span>;<span>ooc_u</span>&<span>quot</span>;<span class="symbol">)</span><span class="symbol">,</span><span>u</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/TimerStart" class="native">TimerStart</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span><span>udg_ooc_dur</span><span class="symbol">,</span><span class="value">false</span><span class="symbol">,</span><span class="keyword">function</span> <span>EndCombat</span><span class="symbol">)</span>
    <span class="keyword">set</span> <span>t</span><span class="symbol">=</span><span class="value">null</span>
<span class="keyword">endfunction</span>

<span class="keyword">function</span> <span>OOC_Conditions</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/boolean" class="type">boolean</a>
    <span class="keyword">return</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/IsUnitType" class="native">IsUnitType</a><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetTriggerUnit" class="native">GetTriggerUnit</a><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/UNIT_TYPE_HERO" class="variable">UNIT_TYPE_HERO</a><span class="symbol">)</span> <span class="symbol">=</span><span class="symbol">=</span> <span class="value">true</span> <span class="keyword">or</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/IsUnitType" class="native">IsUnitType</a><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetAttacker" class="native">GetAttacker</a><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/UNIT_TYPE_HERO" class="variable">UNIT_TYPE_HERO</a><span class="symbol">)</span> <span class="symbol">=</span><span class="symbol">=</span> <span class="value">true</span> <span class="keyword">or</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/IsUnitType" class="native">IsUnitType</a><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetSpellTargetUnit" class="native">GetSpellTargetUnit</a><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/UNIT_TYPE_HERO" class="variable">UNIT_TYPE_HERO</a><span class="symbol">)</span> <span class="symbol">=</span><span class="symbol">=</span> <span class="value">true</span>
<span class="keyword">endfunction</span>

<span class="keyword">function</span> <span>OOC_Actions</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>tar</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/GetAttacker" class="native">GetAttacker</a><span class="symbol">(</span><span class="symbol">)</span>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/unit" class="type">unit</a> <span>temp</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/GetSpellTargetUnit" class="native">GetSpellTargetUnit</a><span class="symbol">(</span><span class="symbol">)</span>
    <span class="keyword">call</span> <span>SetUnitInCombat</span><span class="symbol">(</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/GetTriggerUnit" class="native">GetTriggerUnit</a><span class="symbol">(</span><span class="symbol">)</span><span class="symbol">)</span>
    <span class="keyword">if</span> <span>tar</span> <span class="symbol">!=</span> <span class="value">null</span> <span class="keyword">then</span>
        <span class="keyword">call</span> <span>SetUnitInCombat</span><span class="symbol">(</span><span>tar</span><span class="symbol">)</span>
    <span class="keyword">elseif</span> <span>temp</span> <span class="symbol">!=</span> <span class="value">null</span> <span class="keyword">then</span>
        <span class="keyword">call</span> <span>SetUnitInCombat</span><span class="symbol">(</span><span>temp</span><span class="symbol">)</span>
    <span class="keyword">endif</span>
    <span class="keyword">set</span> <span>tar</span> <span class="symbol">=</span> <span class="value">null</span>
    <span class="keyword">set</span> <span>temp</span> <span class="symbol">=</span> <span class="value">null</span>
<span class="keyword">endfunction</span>

<span class="comment">//======================================================</span>
<span class="keyword">function</span> <span>InitTrig_out_of_combat</span> <span class="keyword">takes</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a> <span class="keyword">returns</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/nothing" class="type">nothing</a>
    <span class="keyword">local</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/trigger" class="type">trigger</a> <span>t</span> <span class="symbol">=</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/CreateTrigger" class="native">CreateTrigger</a><span class="symbol">(</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/Blizzard.j/TriggerRegisterAnyUnitEventBJ" class="function">TriggerRegisterAnyUnitEventBJ</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/EVENT_PLAYER_UNIT_ATTACKED" class="variable">EVENT_PLAYER_UNIT_ATTACKED</a><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/Blizzard.j/TriggerRegisterAnyUnitEventBJ" class="function">TriggerRegisterAnyUnitEventBJ</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/EVENT_PLAYER_UNIT_SPELL_EFFECT" class="variable">EVENT_PLAYER_UNIT_SPELL_EFFECT</a><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/TriggerAddCondition" class="native">TriggerAddCondition</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span><a href="http://wiki.thehelper.net/wc3/jass/common.j/Condition" class="native">Condition</a><span class="symbol">(</span><span class="keyword">function</span> <span>OOC_Conditions</span><span class="symbol">)</span><span class="symbol">)</span>
    <span class="keyword">call</span> <a href="http://wiki.thehelper.net/wc3/jass/common.j/TriggerAddAction" class="native">TriggerAddAction</a><span class="symbol">(</span><span>t</span><span class="symbol">,</span><span class="keyword">function</span> <span>OOC_Actions</span><span class="symbol">)</span>
<span class="keyword">endfunction</span></code></pre></div></div>
and in this case, local trigger can leaks?

ps: based on Darthfett&#039;s vjass code. <a href="http://www.thehelper.net/forums/showthread.php?t=91529" class="link link--internal">http://www.thehelper.net/forums/showthread.php?t=91529</a>
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
whereas now im using JNGP, my jass helper is not working...
... Why?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top