• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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

Status
Not open for further replies.
Level 2
Joined
Oct 3, 2009
Messages
20
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:
JASS:
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
 
Level 5
Joined
Dec 18, 2007
Messages
205
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.
 
Level 2
Joined
Oct 3, 2009
Messages
20
I think you cannot call something that is written below the call line..... maybe you can transfer the function to somewhere on top.

aznricepuff already proved that to be wrong, if u use JASSHelper :)


JASS:
call chainlightning_star.evaluate(param0, param1 ...)
 
Level 4
Joined
Apr 16, 2009
Messages
85
Nah, just use ExecuteFunc(""), it allows forward declarations.

You'll have to pass the parameters to globals and read from there though...

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
 
Level 4
Joined
Apr 16, 2009
Messages
85
I don't think a timer would work. You can't call TimerStart with a function below the call in the script code.

it workes if you do something like this

JASS:
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
 
Level 4
Joined
Apr 16, 2009
Messages
85
its a pretty nice way if you want to use a delay anyway (if not its pointless yes)
 
Status
Not open for further replies.
Top