Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: Function Callbacks  (Read 10941 times)

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Function Callbacks
« on: June 25, 2011, 01:55:46 AM »
Function Callbacks
 
Some of you might be wondering: "How can I execute a code/boolexpr variable at will?"
 
There are only a few answers to this question:

Method 1: Dynamic Triggers

Code: jass  [Select]
  1. local trigger t = CreateTrigger()
  2. call TriggerAddCondition(t, boolexpr)
  3. set t = null

This is a simple concept of it.
What would be even better is doing this:

Code: jass  [Select]
  1. globals
  2.     private trigger t = CreateTrigger()
  3. endglobals
  4.  
  5. function RunBoolexpr takes boolexpr b returns nothing
  6.     call TriggerAddCondition(t, b)
  7.     call TriggerEvaluate(t)
  8. endfunction

This method can also be used for executing code. You'd just have to use
TriggerAddAction and TriggerClearActions instead.

Method 2: Timer Callbacks

This method isn't so good. It appends the current thread, so it will only execute after the
current thread has finished executing.

Code: jass  [Select]
  1. call TimerStart(CreateTimer(),0,false,code)

It only works for boolexprs.
 
Method 3: Function Interfaces

No. Function Interfaces produce a lot of garbage and they spam functions throughout the mapscript.
(If you don't know what a function interface is, basically, it's an object pointing to a certain function-type (Types are defined by their parameters and return-values))

Method 4: ForForce method

It involves creating a global force variable and using it
in the ForForce function. This is the most effective way to execute code.
Note: You must make sure that there will always be only one player in the force.

Method 5: ForceEnumPlayersCounted method

This method should NEVER be used in public resources.
What it does is execute a boolexpr based on the number of players in the map.
Its usage is only recommended for Single-player maps.

Note:
Sometimes, using a global trigger beats any of these methods.
The only case in which it does is when you want to execute multiple boolexprs/codes in the same thread/function.
Instead of constantly executing these functions, we could instead of enqueue them and fire them all as one code.

TriggerAddCondition allows us to enqueue these code/boolexprs into a trigger.
TriggerEvaluate will execute all of these functions.

Code: jass  [Select]
  1. globals
  2.     private trigger t = CreateTrigger()
  3.     private boolexpr array b
  4. endglobals
  5.  
  6. function Example takes nothing returns nothing
  7.     local integer i = 10
  8.  
  9.     loop
  10.         // Enqueue the boolexpr
  11.         call TriggerAddCondition(t, b[i])
  12.         exitwhen i == 0
  13.         set i = i - 1
  14.     endloop
  15.  
  16.     call TriggerEvaluate(t)
  17. endfunction

This method should always be used when you need to execute multiple boolexprs. It isn't helpful with codes though.
The ForForce method is the most effective.

FireCode - Executes Boolexprs and Codes efficiently and Correctly.

End
I hope this tutorial helps =)
Do not credit me for any of this information.
DioD at TheHelper.net is one of the first people to outline the ForForce method.
« Last Edit: January 17, 2012, 08:24:08 PM by Magtheridon96 »

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 983
  • WC3 Models: 15
  • WC3 Tutorials: 12
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: Function Callbacks
« Reply #1 on: June 25, 2011, 07:25:56 AM »
Nice tutorial :)

I was thinking that you should be more specific of which methods are the most recommended (third and fourth)

I think you should add some links to function interfaces method documentation. As you probably are aware, I'm placing the vJASS tutorial in this site for further reference. Just right now I'm going to give you the link to the WC3C link.

http://www.wc3c.net/vexorian/jasshelpermanual.html#funcinterf

« Last Edit: June 26, 2011, 01:50:12 AM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: Function Callbacks
« Reply #2 on: December 28, 2011, 08:58:29 AM »
Well, I've been very inactive :o
I'm going to update this tutorial.
I wrote a library called FireCode that handles execution of code and boolexprs and it allows you to enqueue code and boolexprs.
http://www.hiveworkshop.com/forums/submissions-414/snippet-needs-work-firecode-208389/

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 983
  • WC3 Models: 15
  • WC3 Tutorials: 12
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: Function Callbacks
« Reply #3 on: December 28, 2011, 03:30:01 PM »
Well, I've been very inactive :o
I'm going to update this tutorial.
I wrote a library called FireCode that handles execution of code and boolexprs and it allows you to enqueue code and boolexprs.
http://www.hiveworkshop.com/forums/submissions-414/snippet-needs-work-firecode-208389/
That's just great!!! Go ahead  ;)

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: Function Callbacks
« Reply #4 on: December 29, 2011, 09:32:12 PM »
Is it good enough? Or should I include anything extra to get 'er done? :p

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 983
  • WC3 Models: 15
  • WC3 Tutorials: 12
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: Function Callbacks
« Reply #5 on: December 29, 2011, 09:37:09 PM »
Is it good enough? Or should I include anything extra to get 'er done? :p

Just add the jass tags that I've implemented (the highlighter is in development process, but it's working 50%)

Here's an example:

This code....
Code: [Select]
[code=jass]function interface someFunctionThatReturnsBoolean takes nothing returns boolean
 
function hello takes nothing returns boolean
    return false
endfunction
 
function hi takes nothing returns boolean
    return true
endfunction


produces this presentation:
Code: jass  [Select]
  1. function interface someFunctionThatReturnsBoolean takes nothing returns boolean
  2.  
  3. function hello takes nothing returns boolean
  4.     return false
  5. endfunction
  6.  
  7. function hi takes nothing returns boolean
  8.     return true
  9. endfunction
  10.  


Just add "=jass" to your code tags ;)

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: Function Callbacks
« Reply #6 on: December 29, 2011, 10:14:11 PM »
Done! :D
This tutorial looks better already ^.^
Kudos to you for making those nifty tags :P

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: Function Callbacks
« Reply #7 on: January 17, 2012, 07:54:57 PM »
Well, unfortunately, I recently realized that any "Counted" function fails and can execute more than once.
I guess the best way to execute boolexprs is by having a static trigger, clearing conditions, adding the boolexpr and evaluating the trigger.
It's slow, but it's the only working method :/

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 983
  • WC3 Models: 15
  • WC3 Tutorials: 12
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: Function Callbacks
« Reply #8 on: January 18, 2012, 02:07:24 PM »
Well, unfortunately, I recently realized that any "Counted" function fails and can execute more than once.
I guess the best way to execute boolexprs is by having a static trigger, clearing conditions, adding the boolexpr and evaluating the trigger.
It's slow, but it's the only working method :/
yes, "groupenumcounted" functions are buggy as hell, I avoid them totally. Is better the non counted version, and in the boolexpr function you can implement the counting with coding.


We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

 

My custom made spell damage function

Started by rvonsonsnadtzBoard Coding Help

Replies: 10
Views: 16039
Last post October 13, 2012, 06:20:48 AM
by rvonsonsnadtz
[Snippet] Parabolic Function

Started by moyackBoard Codes & Snippets

Replies: 1
Views: 7121
Last post January 13, 2012, 12:11:45 PM
by Magtheridon96
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!