1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  4. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[vJASS] vJass funnction problems

Discussion in 'Triggers & Scripts' started by nyks078, Nov 26, 2011.

  1. nyks078

    nyks078

    Joined:
    Oct 28, 2011
    Messages:
    23
    Resources:
    0
    Resources:
    0
    I HAVE to make a method that calls ANY function fed. It takes a code call back, which calls the function after the loop.

    vJass
    Code (vJASS):
    static method loopthis takes nothing returns nothing
        //actions here~~~
        loop
            exitwhen i>=f.counter
            if f.this >= f.that then
                 //actions~~~
            else
                 //Here's the thing I mean
                 if not (f.cb == null) then
                     call f.cb()
                 endif
            //actions~~~


    From the code above i wish i'm making myself somewhat clear :) ..
    below is the starting method:

    vJass
    Code (vJASS):
    static method values takes unit u, real h, code cb returns nothing
        local SomeFunc f = f.allocate()
        //blah~~
        set f.cb = cb

        //indexer here
    endmethod


    and my call function

    tired
    Code (vJASS):
    private function Actions takes nothing returns nothing
        //local block
        //actions block
        call SomeFunc.values(caster, GetUnitFlyHeight(caster), function dmgtarget(caster, tgt, lvl) //dmgtarget is NOT a private func


    Is there any other way for me to call a function from outside a library? Because in the case above I kept it in a struct (variable array also does nothing) to be called later... Even PRO IDEAS are well accepted(and i'm eager to learn) for i badly need this for my system :vw_sad:
     
  2. dudeim

    dudeim

    Joined:
    Mar 27, 2008
    Messages:
    111
    Resources:
    0
    Resources:
    0
    Code cannot take parameters as far as I know.
    Also to call a function which is below another function you can do something like this:
    Code (vJASS):

    function a takes nothing returns nothing
    call b.evaluate()//if function b has parameters put them between the "(" ")"
    endfunction

    function b takes nothing returns nothing
    //do stuff
    endfunction
     
     
  3. cohadar

    cohadar

    Joined:
    Jun 16, 2007
    Messages:
    234
    Resources:
    0
    Resources:
    0
  4. dudeim

    dudeim

    Joined:
    Mar 27, 2008
    Messages:
    111
    Resources:
    0
    Resources:
    0
    Function interfaces are horrible you shouldn't use them and function interface != code
     
  5. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    For this, you will most likely need to pass data. One way is with globals, and this works for instantaneous callbacks. For example:
    Code (vJASS):
    globals
        unit caster = null
    endglobals

    function Callback takes nothing returns nothing
        call SetWidgetLife(caster, GetWidgetLife(GetEnumUnit()))
    endfunction

    function Example takes nothing returns nothing
        set caster = GetTriggerUnit()
        call ForGroup(bj_lastCreatedGroup, function Callback)
    endfunction


    That is just an example of passing GetTriggerUnit() across the function using a global. (the function itself doesn't really make much sense)

    For timers, it is a bit different due to the need for multi-unit-instanceability. For more information on vJASS and timers, I recommend that you take a look at this tutorial:
    http://www.thehelper.net/forums/showthread.php/162408-How-to-Use-Timers-in-JASS
     
  6. nyks078

    nyks078

    Joined:
    Oct 28, 2011
    Messages:
    23
    Resources:
    0
    Resources:
    0
    I came from GUI so i know about that stuff =) . But thanks anyways that post gave me an idea.. SOLVED it nOw! haha
     
  7. nyks078

    nyks078

    Joined:
    Oct 28, 2011
    Messages:
    23
    Resources:
    0
    Resources:
    0
    code arrays are not possible so i am using trigger array to be executed after the timer.
     
  8. cohadar

    cohadar

    Joined:
    Jun 16, 2007
    Messages:
    234
    Resources:
    0
    Resources:
    0
    Which is what function interfaces do....