Some way to attach code to struct?

Trollvottel

never aging title
Reaction score
262
its seems that i cant attach code-variables to structs, because no code-array is allowed. any way to do this?
 

Sooda

Diversity enchants
Reaction score
318
Use boolexpr instead and return false in the end. It means you can' t call it as a callback from StartTimer() function. Other way would be to store exact function name as string and then use ExecuteFunc(yourFuncNameString). With ExecuteFunc name needs to be exact or Warcraft will crash.
Then there is triggeraction type what enables you to store trigger action function. But it would be same like using just ExecuteFunc() with func name string because both will create new threads.
What you are trying to do?
 

Trollvottel

never aging title
Reaction score
262
its again for the throw system. i try to throw something and if the unit collides or reaches the ground a specific function will run.
it will be called like this:

TTHROW_ThrowUnitAndDo(thrower, unittothrow,.....,function UserFunc)
 

Sooda

Diversity enchants
Reaction score
318
Check Cohadar TT System, it uses boolexpr to execute functions. They run until boolexpr function returns false, pretty clever.
It means if your unit collided with something you should return in TT System false and before you return false to indicate unit collided start new TT instance by calling boolexpr what should do effects what you want to happen. Actually TT System does already what you want to achieve here. Check his demo map where units slide. Now if unit reaches to max distance boolexpr function will return false. Before that you could call whatever new boolexpr what could for example kill unit and return in first run false. To understand me you should check TT system demo map first.
 

Trollvottel

never aging title
Reaction score
262
thank you for help, it works now not even a return needed, the function runs only once at the end of flying
 

Cohadar

master of fugue
Reaction score
209
For functions that run only once ALWAYS return true or it will desync.
 

Trollvottel

never aging title
Reaction score
262
so if i call TriggerEvaluate(trig) and the function doesnt return anything it desyncs? omg thnx
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
A particular reason for not using function interfaces?
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Nah. Cohadar doesn't understand the beauty of //!textmacros + function interfaces. I'm assuming he doesn't like MaDOS, because of his fanatical campaign of destruction against two very useful things.
 

Vexorian

Why no custom sig?
Reaction score
187
A particular reason for not using function interfaces?

If you made the users pass a boolexpr or trigger, you would generate code that is almost exactly the same as the one generated by function interfaces...
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
And yet you could also make nice syntax sugary programming. For instance:

JASS:
function Ball_Bnc takes BounceEvent BE returns nothing
    call BE.O.Accelerate(0,0,2*BE.O.Speed.Z)
    call SetUnitVertexColor(BE.O.Unit,255,255,255,0)
endfunction


Of course, if you were going to dynamically allocate it, you don't so much need function interfaces, since you are likely using textmacros, and just defining what is happening within the bouncing, etc.
 

Trollvottel

never aging title
Reaction score
262
but why should i do it so complicated if i just can create a trigger array, add the condition and evaluate the trigger?
 

Cohadar

master of fugue
Reaction score
209
A particular reason for not using function interfaces?

Function interfaces have ugly syntax in vJass, so they kind of fail in their purpose to be syntax sugar.

but why should i do it so complicated if i just can create a trigger array, add the condition and evaluate the trigger?

You should use TT, it really does not get much simpler than that.
If I can use it for physics engine in pyramidal you can use it for your jump/throw system.
 

Trollvottel

never aging title
Reaction score
262
i used it as timer <.< sure
but i think you understand me wrong. at the end of the running I just call a userfunc and for this i really dont need TT because its just.... one call without anything else but I have to use TriggerEvaluate()
 

Cohadar

master of fugue
Reaction score
209
Oh I see.
Well then use function registration like in TT.
But instead of condition use Action and do TriggerExecute on a trigger that has userFunction as Action.
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Is his system not dynamic (with dynamic creation/destruction)? I mean, I suppose it doesn't even matter, since I can't see a situation where you would be constantly creating and destroying these actions...
 

Trollvottel

never aging title
Reaction score
262
i can. its for my throw system. you throw the unit/projectile and when it hits the ground, this function is called. so thats a good solution for it
 

Vexorian

Why no custom sig?
Reaction score
187
For your application it would be a capital sin not to use interfaces, your users are most likely going to need to specifiy data as well, not just a function.




Function interfaces have ugly syntax in vJass, so they kind of fail in their purpose to be syntax sugar.
Not buying it.

Edit: I mean, if you were to ask a user, what's better:

"make a boolexpr and add it as an argument to my function"
"Add your function as code argument to my function"
"Type FunctionInterfaceName.functionname "

All three of them look like equal non-sense to me. But at least the function interface will save every one work, you will not have to bother creating triggers at map init your self. And you can just as easily decide between .evaluate or .execute.

I was thinking on making just functionname work, or perhaps I'll make up something like "somekeyword functionname" to make it look like Jass' code but I've been too busy.

They are just a workaround for people that don't want to use interfaces, anyway...
 

Trollvottel

never aging title
Reaction score
262
For your application it would be a capital sin not to use interfaces, your users are most likely going to need to specifiy data as well, not just a function.

i dont understand. my users get globals they can handle with for this function, i dont think there will be a problem, another reason for me not to use interfaces for me is that i never did and dont know how i should do it here
 
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