Using Code for dynamic functions, is it possible? +rep for answers

luorax

Invasion in Duskwood
Reaction score
67
Well, function interfaces can do this for you, although you can achieve something similar by using globals to transfer data between functions:

JASS:
scope foo

    globals
        private real TempValue
    endglobals
    private function CustomFunction takes code c,real r returns nothing
        set TempValue=r
        call ForForce(bj_FORCE_PLAYER[0],c)
    endfunction
    private function MultipleTen takes nothing returns nothing
        set TempValue=TempValue*10
    endfunction
    private function MultipleTwo takes nothing returns nothing
        set TempValue=TempValue*2
    endfunction
    private function Echo takes string s returns nothing
        call DisplayTextToPlayer(GetLocalPlayer(),0.,0.,s)
    endfunction
    private function TestRun takes nothing returns nothing
        call CustomFunction(function MultipleTen,50.)
        call Echo(R2S(TempValue)) //Displays 500.00
        
        call CustomFunction(function MultipleTwo,50.)
        call Echo(R2S(TempValue)) //Displays 100.00
    endfunction
    
endscope


You have to write more, but it's actually faster.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
so basically you use global variables as the arguments and
[ljass]call ForForce(bj_FORCE_PLAYER[0], c)[/ljass]
 

luorax

Invasion in Duskwood
Reaction score
67
Exactly. That's the way function interfaces work tho', but they use trigger evaluations rather than [ljass]ForForce[/ljass], which is slower.
 

Dirac

22710180
Reaction score
147
I think ForForce is actually slower from some tests i ran a while back.
Anyways, there are always ways to avoid the use of dynamic codes or function interfaces, such as textmacros or module implementation.
 

luorax

Invasion in Duskwood
Reaction score
67
It's interesting if that's true (IMO). But still, function interfaces create some weird duplications and useless things that can be avoided with my code.
Hell, choose the way you like more, the speed difference isn't noticeable (unless you spam them; but I guess you're not planning on doing it)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
well i was thinking about making a spell that applies effects of similar spells cast recently by saving the functions and arguments for the spell if made in jass that is

working on a lotta different things, and that seemed like an easy way to do a spell similar to that
 

Dirac

22710180
Reaction score
147
For that we have "SpellStruct" by Nestharus and many other libraries (like "Missile") that help you to code spells by reducing the code length from 400 lines to 20
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top