wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 01-08-2006, 06:50 PM   #1
Blade.dk
.
 
Blade.dk's Avatar


Respected User
 
Join Date: May 2005
Posts: 1,990

Submissions (15)

Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)Blade.dk is a glorious beacon of light (418)

Approved Map: Azeroth's Arcane ArenaSpell session 01 winner

Send a message via MSN to Blade.dk
Default How to use the ExecuteFunc native

As lots of people don't know the ExecuteFunc native, here is a brief tutorial about how to use it.

NOTE: This tutorial requires you to know, at least, the basics of JASS. If you don't know it, search the web for tutorials focused on that, I'd recommend Vexorian's Introduction to JASS.

Table of contents
1. What is ExecuteFunc?
2. Which functions can I use with it?
3. How exactly do I call it?
4. Give me some examples!
5. Are there any problems with ExecuteFunc?

1. What is ExecuteFunc?

ExecuteFunc is just a native, but one of the most useful natives.

It takes a function's name as a string argument, and executes the function in another thread.

This means, that the executed function can use waits without interrupting the calling thread, and as it will remember event responses, it allows you to use waits in for example ForGroup and TimerStart calls.
Moreover, it's the only way to have forward references in JASS.

2. Which functions can I use with it?

You can use ExecuteFunc with any function that takes nothing, the function may be constant and is allowed to return a value, even though you won't be able to access that value, unless the function stores it in a global.

As said above, the ExecuteFunc native allows forward references, so the function may be below the call in the map's script file.

3. How exactly do I call it?

Calling ExecuteFunc is simple when you know JASS. You just call it with the function's name as a string argument to execute the function.

The funcName argument is case sensitive and has to be spelled correctly; else it'll cause crashes.
You can use things like concatenation, just be sure that the string it ends up with is valid.

It won't cause crashes if you use null or "" as argument.

You can make it execute the function it is called from within, but be sure you prevent it from turning into an infinite loop without pauses, as that will cause the map to crash.

4. Give me some examples!

Basic example of calling it:

Collapse JASS:
function Hello takes nothing returns nothing
    call ExecuteFunc("Hi")
    call BJDebugMsg("Hello")
endfunction

function Hi takes nothing returns nothing
    call BJDebugMsg("Hi")
endfunction

When the Hello function is called, this will display the text:

Hi
Hello

The reason "Hi" is displayed before "Hello" is that the ExecuteFunc call in the Hello function is located over the BJDebugMsg call. This is also an example of a forward reference using ExecuteFunc.

You could have replaced the Hi function with the following function without problems:

Collapse JASS:
constant function Hi takes nothing returns string
    return "This is idiotic, but it's still possible."
endfunction

Before I talked about having TriggerSleepAction calls in a ForGroup callback function. Example:

Collapse JASS:
function Enum2 takes nothing returns nothing
    local unit e = GetEnumUnit() // Store the enumerated unit in a local variable
    call TriggerSleepAction(5) // Wait five seconds
    call KillUnit(e) // Kill the unit
    set e = null // Set the local to null to avoid memory leaks
endfunction

function Enum takes nothing returns nothing
    call ExecuteFunc("Enum2") // Let's execute the Enum2 function to allow waits.
endfunction

...
    call ForGroup(someGroup, function Enum) // will kill all units in the 'someGroup' group after five real-time seconds.
...

Normally a TriggerSleepAction call would halt the ForGroup call, but not here, as the waits are in the Enum2 function that is executed with ExecuteFunc.

It also shows that event responses, like GetEnumUnit, works completely fine with ExecuteFunc.

5. Are there any problems with ExecuteFunc?

Yes. It will crash your map if the funcName argument is not a valid function name, but this won't happen if the user, you, know what he does.

Another problem occur when you use map protectors like Heavylocker's or Extprotect's function obfuscating method that renames functions to random things. As they don't change the contents of the strings having the same name as functions, it will cause crashes when it's called.

The solution would be using Vexorian's Map Optimizer, as long as you just use the strings directly (without using concatenation or things like that). The other solution would be to avoid using those tools, or at least avoid using those obfuscation methods.

I hope this helped somebody.
- Blade.dk
__________________
Spell Making Course: Part 1: Making a simple stomp spell.
I wonder if I'll ever finish part 2.
Blade.dk is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-15-2006, 04:32 AM   #2
masda70
User
 
Join Date: Nov 2003
Posts: 233

Submissions (1)

masda70 has a spectacular aura about (128)

Default

I just came across this tutorial and I was surprised to read that TriggerSleepAction halts ForGroup callback. I've been using that all the time and also just tested it now, it works just fine!
masda70 is offline   Reply With Quote
Old 04-15-2006, 05:29 AM   #3
PipeDream
Moderator
 
PipeDream's Avatar


Code Moderator
 
Join Date: Feb 2006
Posts: 1,405

Submissions (6)

PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)PipeDream is a glorious beacon of light (463)

Default

I just tested as well. Seems to still not be working though... Post your test, Masda?
PipeDream is offline   Reply With Quote
Old 04-16-2006, 07:56 PM   #4
masda70
User
 
Join Date: Nov 2003
Posts: 233

Submissions (1)

masda70 has a spectacular aura about (128)

Default

Hmm nevermind, I thought this meant a for group callback was a single thread that would run each wait one after another thus delaying the whole execution of every unit to go one after the other hehe, I see the problem is different. Great info then!

Last edited by masda70 : 04-16-2006 at 07:57 PM.
masda70 is offline   Reply With Quote
Old 04-19-2006, 07:52 PM   #5
BertTheJasser
xyzi - our universe
 
BertTheJasser's Avatar
 
Join Date: May 2005
Posts: 742

Submissions (2)

BertTheJasser has a spectacular aura about (111)BertTheJasser has a spectacular aura about (111)BertTheJasser has a spectacular aura about (111)BertTheJasser has a spectacular aura about (111)

Default

He starts
Collapse JASS:
Enum2
every time in an extracted single thread. This alows him to use TriggerSleepAction or PolledWait or any custom wait method.

Great tut.
__________________
Note: Bye... I had a lot of fun here!
Special thanks to Vexorian who helped me learn jass, the real jass and always helped me when problems occured, I would call him somehow my mentor. Pipedream, who made amazing Grimoire and helped me acclerating my map (currently at 99% finished, no developement atm).

Vote for Linux Ports in general of Blizzard products: http://www.PetitionOnline.com/ibpfl/
BertTheJasser is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 04:30 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services