• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] vJass funnction problems

Status
Not open for further replies.
Level 3
Joined
Oct 28, 2011
Messages
23
I HAVE to make a method that calls ANY function fed. It takes a code call back, which calls the function after the loop.

JASS:
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:

JASS:
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

JASS:
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:
 
Level 4
Joined
Mar 27, 2008
Messages
112
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:
JASS:
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
 
For this, you will most likely need to pass data. One way is with globals, and this works for instantaneous callbacks. For example:
JASS:
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
 
Level 3
Joined
Oct 28, 2011
Messages
23
For this, you will most likely need to pass data. One way is with globals, and this works for instantaneous callbacks. For example:
JASS:
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

I came from GUI so i know about that stuff =) . But thanks anyways that post gave me an idea.. SOLVED it nOw! haha
 
Status
Not open for further replies.
Top