Store function ??

darkbeer

Beer is Good!
Reaction score
84
Hey,
just want to ask what is the best way to store a function, so i can execute it later

heres an example of what i mean^^

lets say i made i missile system for spells, so if a unit cast a spell called fireball it will create a dummy and moves it to the target using a timer, now if anything is in the way (other unit, trees ....) the ball will execute a function MyFunc that deals aoe damage and casts another spell on all units in the area.

So now i want to do the same with an iceball, so i just need to change the executed function to MyFunc2, to do other things.

but how do i execute a function giving it arguments and how should i know which function to execute, im using a struct, so i might should use methods, (i heard sth about interfaces being usefull at such things)

maybe someone has a better idea than me^^ thx in advance
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
You can do it in two ways (using vJass, you can do it in vanilla jass too but that's more hackish.).

The first one is the struct method you already mentioned, the second one is using function interfaces. Structs are more flexible since you can have additional data stored in the struct but they require some more typing.

JASS:
interface OnHitAction
     public method onHit takes <something> returns <something>
endinterface

struct FireHit extends OnHitAction
     public method onHit takes <something> returns <something>
         // do anything
     endmethod
endstruct
// ...
local OnHitAction action = <get it some way>
call action.onHit(...)
 

darkbeer

Beer is Good!
Reaction score
84
okay, ill try to code it and post my result^^

thanks a lot :)

hm, what do you think would be the best way to get the function??
example again^^:
lets say i make 2 spells: fireball , iceball, both use the same missile system, but different functions when the target is hit (fireexpl, coldexpl) and both need different arguments, is it somehow possible to say exactly which function it should call and what arguments i need to pass? maybe wth a string or something like that xD

how would it be done, or would it be better to make 2 struct types with interfaces and the same method?

thx for any help in advance

EDIT: guess i'll do one interface, with all the important data and pass the structs to the function^^
 
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