HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Creating functions ingame?

04-24-2004, 03:40 PM#1
fugly
Is there any anyway to create a function ingame?
04-24-2004, 04:06 PM#2
Narwanza
No, but you shouldn't have to. Tell us what you want to do.
04-24-2004, 06:02 PM#3
fugly
pretty much an AI for ranged units, as differnent unit types enter the feild a new function should be created that order these new unit types to also do it.
04-24-2004, 10:17 PM#4
Narwanza
ummm.... you are confusing functions with triggers. Triggers and functions are different. A trigger can have many function, while a function contains no triggers. Functions are the basic unit of structure in JASS. Now for what you are doing, you are going to have to make several different functions and then add them to triggers as needed. If you give me more specific information I could write an example for you.
04-25-2004, 03:03 AM#5
Cubasis
So yes, if I want to assign a "function" to each unit I create....I would then do cirka the following somewhere:

local trigger trig = CreateTrigger()
call TriggerAddAction(trig,MyAISystem)
call TriggerRegisterTimerEvent(trig,0.5,true) //not sure about the func-name, just writing from memory)
call SetHandleHandle(trig,"Unit",MyUnit)

So, first of all, the above code uses kattana's SetLocalHandle functions. They allow you to attach whatever you want to anything, so you could attach your own custom integer-value to a unit...or as in this case, assign the unit I want the trigger to control...to the trigger. (here: http://kattana.users.whitehat.dk/forside.php)
Also, in that example, the function called MyAISystem would then take this attached handle, and do whatever it wants with it. Note that in this example I tell it to run every 0.5 second, but you might prefer to just have your function run forever with "waits".

Anyways, another difference between triggers and functions is that...as Narwanza said, functions are the basic building blocks of your code...they are pre-declared/defined, and are made to do some job. Triggers however....are Created at run-time, they are a object, which you can attach onto a number of Actions, Events and conditions. Actions and Conditions are in fact just "functions"....

Cubasis