Calling function that is lower?

WayTooShort

New Member
Reaction score
4
For the sake of simplicity I will use this code:

JASS:
function asdf takes nothing returns nothing
    call fsda()
endfunction

function fsda takes nothing returns nothing
    call asdf()
endfunction


How can I make the upper function to be able to call the lower function without syntax error?
 

tooltiperror

Super Moderator
Reaction score
231
Two ways.

1) Put the functions in libraries in order of requirement.

JASS:
// untested
library asdf uses fsda
	function asdf takes nothing returns nothing
		call fsda()
	endfunction
endlibrary 

library fsda
	function fsda takes nothing returns nothing
	endfunction
endlibrary


2) If you want to do exactly what you did in your example you could attach the code as a boolexpr to a trigger and then evaluate the trigger. I think this will be slower than a direct function call, but who really cares that much, unless you're calling them 10 times a second.

JASS:
// untested
globals
	private trigger asdf_trigger = CreateTrigger()
	private trigger fsda_trigger = CreateTrigger()
endglobals

function asdf takes nothing returns nothing
	call TriggerEvaluate(fsda_trigger)
endfunction

function fsda takes nothing returns nothing
	call TriggerEvaluate(asdf_trigger)
endfunction

function onInit takes nothing returns nothing
	call TriggerAddCondition(asdf_trigger, Condition(function asdf))
	call TriggerAddCondition(fsda_trigger, Condition(function fsda))
endfunction


You might also be interested in the idea of a keyword.
 

tooltiperror

Super Moderator
Reaction score
231
Yeah, a .evaluate will be preprocessed to some trigger magic ([LJASS]if (TriggerEvaluate(t)) {TriggerExecute(t)}[/LJASS]) if memory serves correctly.

I'd be happy to compile an example for you if you'd like, to see if it really does compile that way.
 

tooltiperror

Super Moderator
Reaction score
231
Yeah, JASSHelper uses ExecuteFunc.

JASS:
function x takes nothing returns nothing
	call y.evaluate()
endfunction

function y takes nothing returns nothing
endfunction

function main takes nothing returns nothing
endfunction


Is compiled to:

JASS:
globals


//JASSHelper struct globals:
trigger array st___prototype1

endglobals

function sc___prototype1_execute takes integer i returns nothing

    call TriggerExecute(st___prototype1<i>)
endfunction
function sc___prototype1_evaluate takes integer i returns nothing

    call TriggerEvaluate(st___prototype1<i>)

endfunction

function x takes nothing returns nothing
	call TriggerEvaluate(st___prototype1[(1)]) // INLINED!!
endfunction

function y takes nothing returns nothing
endfunction

function main takes nothing returns nothing

call ExecuteFunc(&quot;jasshelper__initstructs4004&quot;)

endfunction


//Struct method generated initializers/callers:
function sa___prototype1_y takes nothing returns boolean

    return true
endfunction

function jasshelper__initstructs4004 takes nothing returns nothing
    set st___prototype1[1]=CreateTrigger()
    call TriggerAddAction(st___prototype1[1],function sa___prototype1_y)
    call TriggerAddCondition(st___prototype1[1],Condition(function sa___prototype1_y))

endfunction
</i></i>


I'd be curious to see if this could be sped up (JASSHelper isn't notorious for it's quick code, namely allocation methods).
 

WayTooShort

New Member
Reaction score
4
Thanks, the fsda.execute works fine for me.

Now I also encountered a similiar problem with my another trigger with timers, it kinda looks like this:

JASS:
function asdf takes nothing returns nothing
    local timer abc=GetExpiredTimer()
    call TimerStart(abc, 1.00, false, function fsda)
endfunction

function fsda takes nothing returns nothing
    local timer abc=GetExpiredTimer()
    call TimerStart(abc, 1.00, false, function asdf)
endfunction


How can I make it accept fsda.execute in the TimerStart?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
You would do this:
JASS:
globals
    timer abc2 = null
endglobals

function asdf takes nothing returns nothing
    set abc2 = GetExpiredTimer()
    call ExecuteFunc(&quot;bababubu&quot;)
endfunction

function fsda takes nothing returns nothing
    local timer abc=GetExpiredTimer()
    call TimerStart(abc, 1.00, false, function asdf)
endfunction

function bababubu takes nothing returns nothing
    call TimerStart(abc2, 1.00, false, function fsda)
endfunction


Or, instead of executefunc you can use .execute or .evaluate or the keyword or whatever. It is up to you.
 

Bribe

vJass errors are legion
Reaction score
67
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top