Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Call Function A From Function B - and A is Declared after B :/

Discussion in 'Triggers & Scripts' started by Kukeiko, Oct 18, 2009.

  1. Kukeiko

    Kukeiko

    Joined:
    Oct 3, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    Another Question today :3


    I want every Hit of my Custom Chain Lightning be able to cast another Chain Lightning, which means, that i have to access the Function that is declared "underneath"

    Example:
    Code (vJASS):

    function chainlightning_loop (params)

    do stuff

    % chance to call function chainlightning_start

    endfunction


    function chainlightning_start (params)
    call chainlightning_loop(params)
    endfunction
     


    However, this will result in "Error: Awaiting Function Name" (and JassCraft: undeclared Function)
    And yes, i DO know that this is recursive, however, with the % chance it will not result in an endless sea of wtfoverkill.

    I hope there is some way to declare functions beforehand, like the headers @ C++ :/


    Thanks in Advance! :)
    ofcourse +rep for every useful answer
     
  2. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
  3. bReathl3sS

    bReathl3sS

    Joined:
    Dec 18, 2007
    Messages:
    205
    Resources:
    0
    Resources:
    0
    you cannot call "call function chainlightning_start" in the chainlightning_loop because it is below and oyu cannot trigger sth that is below?
    or am i totally dumb?oO
    i would use the chainlightning anyhow triggered by a global trigger and then call the tirgger like in GUI.
     
  4. Kukeiko

    Kukeiko

    Joined:
    Oct 3, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
  5. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    I think you cannot call something that is written below the call line..... maybe you can transfer the function to somewhere on top.
     
  6. Kukeiko

    Kukeiko

    Joined:
    Oct 3, 2009
    Messages:
    20
    Resources:
    0
    Resources:
    0
    aznricepuff already proved that to be wrong, if u use JASSHelper :)


    Code (vJASS):
    call chainlightning_star.evaluate(param0, param1 ...)
     
  7. Reaper2008

    Reaper2008

    Joined:
    Jul 27, 2008
    Messages:
    1,117
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Nah, just use
    ExecuteFunc("")
    , it allows forward declarations.

    You'll have to pass the parameters to globals and read from there though...
     
  8. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    Which is why JassHelper PWNZ0RZ!!!

    But, yeah, seriously, don't try to discourage people from using vJass...
     
  9. Void

    Void

    Joined:
    Apr 16, 2009
    Messages:
    85
    Resources:
    0
    Resources:
    0
    using ExecuteFunc() is actually really bad as its another major screwup by blizzard
    1. its utterly slow
    2. it seems to search the whole map script for a function with that name you passed (which means the farer ExecuteFunc is away from your actual function the slower it gets - and - if its too far away it will just fail)
    3. if you pass the wrong function name it crashes
    4. it starts a new thread so you can't pass any values back
    5. vJass version is safer, faster and nicer anyway (and if you want to start a new thread you can still use .execute() to ovoid hitting the OP-Limit)

    Oh btw: timers are a possible solution for that problem too
     
  10. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    I don't think a timer would work. You can't call TimerStart with a function below the call in the script code.
     
  11. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,220
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    So just stick to the interface functions. You will need them later aswell, and its quite good.
     
  12. Void

    Void

    Joined:
    Apr 16, 2009
    Messages:
    85
    Resources:
    0
    Resources:
    0
    it workes if you do something like this

    Code (vJASS):

    scope Test initializer init
    globals
        code bla
    endglobals

    function a takes nothing returns nothing
        call TimerStart(...., bla)
    endfunction

    function b takes nothing returns nothing
        call TimerStart(...., function a)
    endfunction

    function init takes nothing returns nothing
        set bla = function b
    endfunction
    endscope
     


    o/c you would have to do some attaching but it does actually work
     
  13. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,298
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    But it's a long-winded, pointless way.
     
  14. Void

    Void

    Joined:
    Apr 16, 2009
    Messages:
    85
    Resources:
    0
    Resources:
    0
    its a pretty nice way if you want to use a delay anyway (if not its pointless yes)