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?
 
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 ;)
 
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.
 
> can't i use a function in one trigger in another trigger?

Use a library. :p
 
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
 
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>
 
whereas now im using JNGP, my jass helper is not working...
... Why?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top