Execute a code variable for callback?

fizix

New Member
Reaction score
0
I want to make my own callback function that takes a code variable as a parameter and executes it. Is there any way in JASS to do this? I'm getting desperate and this seems to be the only solution.

JASS:

function whatever takes code callback returns nothing
   call callback() // ? ? ?
endfunction
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
In vJass, there are function interfaces:

JASS:
function interface AMethod takes integer this returns nothing

function foo takes AMethod bar, integer AnArgument returns nothing
    call bar.execute(AnArgument)
endfunction


There is also the idea of using a trigger:

JASS:
function foo takes code bar returns nothing
    local trigger t = CreateTrigger()
    call TriggerAddAction(t,bar)
    call TriggerExecute(bar)
    //My trigger is leaked, but destroying dynamic triggers is bad, what do I do?!
endfunction
 

DioD

New Member
Reaction score
57
struct using trigger evaluation.
dont know about anyone posted direct execute before me.

Here is my sample of direct execution usage, you may cut unload detection and use direct exec only.
http://www.thehelper.net/forums/showthread.php?t=158295


JASS:
    set FFCXZ__ForceExec = CreateForce()
    call ForceAddPlayer(FFCXZ__ForceExec,Player(0))

+
JASS:
        call ForceEnumPlayers(FFCXZ__ForceExec,ExecData<i>)</i>


It will execute any given code.
Also you may use ForForce with code param, it will do same, but code cannot be placed into array.
 

Bribe

vJass errors are legion
Reaction score
67
It will execute any given code.
Also you may use ForForce with code param, it will do same, but code cannot be placed into array.

Wow :O

Finally, a way to execute code without needing expensive triggers! Very nice work!
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Nice, but with functions with arguments and returns something else than a boolean i would still use function interfaces instead, just because it makes the code neater (the vJass code not the jass one ofc)

Also i suppose ForceEnum doesn't open a new thread (reset limit op) like TriggerEvaluate/Execute ?
That's not bad, and most of time even better, it's a just a thing to keep in mind before using it.
 

DioD

New Member
Reaction score
57
it open new thread, also you may add one more player to force and practice "parralell calculations"
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Interesting.
But since wc3 triggers don't support multi threading i'm wondering what happens really.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Double post !

ForForce also opens a new thread, but i assume you already know that.
I'm pretty suprised of that, i always believed it didn't, i was wrong.

Sure, if you want to use a boolexpr variable array (because we aren't allowed to use a code array) then you must use ForceEnumPlayers, that's the reason of your choice.

I suggest a little thing, instead of using Player(0) you could use GetLocalPlayer(), it should be safe and map independant, at least in your script example.
Ofc the coder shouldn't use GetFilterPlayer at all in such code, at least if he doesn't know perfectly what he is doing.

Indeed for some reason if the player red slot is setted to "no player", then you can't use this player with ForForce/ForceEnumPlayers.
I mean the Player(0) won't be added to the force.
 

DioD

New Member
Reaction score
57
this is wrong (or you are doing something wrong) but this code allow to add any player to force, also player 15 always online.

peronally i do not recomend local player anywhere, it may async replays, ever if game run smooth.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
this is wrong (or you are doing something wrong) but this code allow to add any player to force, also player 15 always online.

peronally i do not recomend local player anywhere, it may async replays, ever if game run smooth.

No i've tested, leave a slot to "none player" in player property (SetPlayerController) and try to add a player to the force, you will see the player won't be added to the force, so the code won't be executed since the force will be empty.
Now do the same with a player controller or an computer, i haven't tested with other mapcontrols, but the player slot status doesn't seem to matter.

For the async replays, i don't see how it could desync, is it a personal experience or just a guess ?

EDIT :

Ok i'm wrong but it's a lot tricker, let's test that :

JASS:
library Something initializer onInit

globals
    force F
endglobals

private function callback takes nothing returns nothing
    call BJDebugMsg(&quot;for force , enum player : &quot; + GetPlayerName(GetEnumPlayer()))
endfunction

private function filter takes nothing returns boolean
    call BJDebugMsg(&quot;filter , filter player : &quot; + GetPlayerName(GetFilterPlayer()))
    return false
endfunction

private function onInit takes nothing returns nothing
    call TriggerSleepAction(0)
    set F = CreateForce()
    //player(3) and 4 are empty slots players controllers
    call ForceAddPlayer(F,Player(3))
    call ForceAddPlayer(F,Player(4))

    call ForForce(F,function callback)
    call ForceEnumPlayers(F,Filter(function filter))
endfunction

endlibrary


Also, test it with an empty but created force.

In fact ForceEnumPlayers will fire with all playing players (at least computers and actually playing players and also maybe leavers, i haven't tested with the others mapcontrollers), no matter if they are in the force or not.
So you can't use ForceEnumPlayers like that, it's to much map dependant.
 

DioD

New Member
Reaction score
57
well, never tested enum in multiplayer, my bad. (since i always ran test alone, this function always ran fine for player(0))

yes it enum every active player, not players already in force, but, its still possible to use.

JASS:
library Something initializer onInit

globals
    force F
    boolean B
endglobals

private function filter takes nothing returns boolean
    if B then
        return false
    endif
    set B = true
    call BJDebugMsg(&quot;filter , filter player : &quot; + GetPlayerName(GetFilterPlayer()))
    return false
endfunction

private function onInit takes nothing returns nothing
    set F = CreateForce()
    call TriggerSleepAction(0)
    set B = false
    call ForceEnumPlayers(F,Condition(function filter))
endfunction

endlibrary


Since there is always at least one player, it will work fine in any case.

localplayer() in replay will be player 0 always, if player 0 does not exist ingame game, it may cause problems.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Ofc i thought about that, but you have to agree that's silly to open X threads instead of one, in this way the vJass solution is better, even if it needs to create a trigger in map initialisation.
It was a clever idea though.
It is not your fault, how ForceEnumPlayers works is totally senseless, we couldn't imagine that.
EDIT : Hmm, in a second though that makes sense, that's kinda the same with GroupEnum after all.

About local player i'm the one which posted a thing about the replays (at least i haven't seen someone else), and i can say that's not always Player(0), it's the first human player which played in the game.
And it seems it only matters for things which doesn't interact with the gameplay, like texttags, text messages and so one.
I haven't heavily tested it but i haven't made a successful desync with a replay and GetLocalPlayer.
For example a trigger with the event "an unit is selected by player X", if i select only for player 2 with GetLocalPlayer, and inside the trigger condition/action kill all units of player 2.
In replay the same happens, even if GetLocalPlayer returns Player 1.
I can't explain why but that's it.

I know it because in first time i thought i could use GetLocalPlayer to know if it's a replay or not, without any success.
 

DioD

New Member
Reaction score
57
this anyway possible to place one unit inside corner and use this unit with GroupEnumRect.

also its enemy-ally enums, in most cases player 15 have only shops, soo we can make everyone enemy for him, expect one ally.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
this anyway possible to place one unit inside corner and use this unit with GroupEnumRect.

also its enemy-ally enums, in most cases player 15 have only shops, soo we can make everyone enemy for him, expect one ally.

Well, creating an unit just for that is way to much overkill.
It's time to recognize that vJass way (function interface/.evaluate/.execute) is actually the best :D

For personal purpose you can still use that, especially if you already use a dummy unit, but we can't seriously recommend it for the others, can we ?
 

DioD

New Member
Reaction score
57
there is no best solution.

for single run we can use enum
for multiple static calls we can use trigger

with vJass we dont have control over code, its just like GUI

i cant cache evaluate calls for futher use, cos vJass decide what and how to do, not me.
95% of users enjoy this by using GUI, vJass, cJass, zinc or some system they dont ever understand.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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