• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] "code" Variable Type

Status
Not open for further replies.
Level 2
Joined
Sep 21, 2013
Messages
22
I've been wondering how to use the variable type "code" in creating a function that can execute a function given to it.

For instance;
JASS:
globals
    code Func
endglobals

function SetFunction takes code codeFunc returns nothing
    set Func = codeFunc //I want to use the function later, So I store it in a global.
endfunction

function RunFunction takes nothing returns nothing
    //Not sure what to put here.
endfunction

Then in another trigger

JASS:
function This takes nothing returns nothing
    //...
endfunction

function That takes nothing returns nothing
    call SetFunction(function This)
endfunction

I know I can store it in a trigger and just execute the trigger, but I was wondering if that was truly the best way. Anyone's thoughts? I can't seem to find anything relating to this.
 
Level 2
Joined
Sep 21, 2013
Messages
22
Mainly because I have a cinematic system which uses triggers to store the cinematic data, then runs through the data. The functions needing to be stored so they can be used later on because they are not called immediately.

It's mainly so I can use this system without repeating the same actions each trigger (timers, etc. when I can call it from the system itself.)

Anyway, thanks, I will try it out :)

UPDATE: No dice :( I think I may have to just store it in a private trigger.
 
Level 2
Joined
Sep 21, 2013
Messages
22
It's mainly so I don't have to change the code in my system to run a function from another library.

For instance, here's an example on what I'm doing;

JASS:
Trigger 1:
The game starts
Add transmission from U1 saying S1 to Trigger2
Add transmission from U2 saying S2 to Trigger2
Add transmission from U1 saying S3 to Trigger2
Add a function to run when the cinematic is over to Trigger2

So trigger 1 sends data to trigger 2 to store for the cinematic.

JASS:
Trigger 2:
Run all transmissions
Run stored function

Trigger 2 then runs all the data it has stored. I can make as many triggers similar to trigger 1 as I would like without changing trigger 2 at all and still have everything run as planned. The only way to know what function that it needs to run in the end is to store it for later use in its own trigger.

The main reason is just so I can have a skippable cinematic :) It might be a system I release later on, I'm fairly confident in how it's functioning thus far.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
I never used it, but this should also work.
JASS:
globals
    private trigger MyTrigger
    private triggercondition triggercond//array?
endglobals

   private function AddFunctionExample takes code func returns nothing
        local boolean expression = Condition(func)
        set triggercond          = TriggerAddCondition(MyTrigger, expression)
        call TriggerEvaluate(MyTrigger)
        call TriggerRemoveCondition(MyTrigger, triggercond)
        set triggercond          = null
        set expression           = null
    endfunction

I suggest you just make a second trigger and evaluate it when the cinematic in question is over or just call that function.
Wouldn't that work for you:
JASS:
function xy takes nothing returns nothing
    //......
    //cinematic is over
    call FunctionYouWantedToAdd()
endfunction
If possible don't make easy things complicated.
 
@BPower: It works fine with the optimizer. That was just a rumor spread around a while back.

Thankfully, ExecuteFunc() isn't as bad as it used to be. It was previously avoided because it would crash when you input a nonexistent function name, but that was fixed some time ago. Now the only real disadvantage is speed, which is negligible if you're not doing it periodically.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I even prefer function interface than ExecuteFunc, since we are talking about vJass.
Not pop an error on save if you misstype is definetely a con, now if you play with strings you can do "cool" stuff with ExecuteFunc, but frankly i've never needed it.
I mean if code is not enough i went for function interface.
 
Status
Not open for further replies.
Top