Difference between revisions of "Activation Functions"
Jump to navigation
Jump to search
update of old text
imported>Guidobot (put script back to correct) |
imported>Guidobot (update of old text) |
||
Line 2: | Line 2: | ||
In-game functions are basically scripts on objects (placed in the game) that can be called from any other script. You can also pass variables in and out of that function easily without reference to independent global variables. | |||
In-game functions are easier to create | In-game functions are easier to create and do not have the restrictions that Stage functions have, e.g. number of lines, reference object calls, variable definiton, etc. You can do almost anything you can from any other script with them, but you might also find them useful to avoid writing huge scripts or as an alternative way to add global variables to the game (one that is more forgiving to script updates than quest script variables). A minor variation on the basic principle allows you to also use them for static 'spell' effects. | ||
CREATING AN IN-GAME FUNCTION | |||
1) Copy any object that takes a script ( | 1) Copy any object that takes a script (e.g. Gold or an Evil Stone). Rename to, e.g., TargFunction. | ||
2) Place a copy somewhere suitable in the world - preferably where you already have something or in your own cell. | 2) Place a copy somewhere suitable in the world - preferably where you already have something or in your own cell. | ||
3) Mark the object | 3) Mark the object persistent. Give it a suiable name, e.g. TargFunc01. | ||
4) Place a script on the object to do | 4) Place a script on the object to do your function. Typically this will just consist of the OnActivate block and variables that can be accessed from other scripts. (See example script below.) | ||
5) Call this function | 5) Call this function using the Activate command. (See below.) | ||
STATIC FUNCTIONS | |||
If you really want a static function then your best option is to use a remote persistent object - i.e. a true world activator object (e.g. a switch) placed in some hidden location. To call your function: | |||
[set IGFActRef.someInputVar to someInput] | |||
IGFActRef.Activate player 1 | |||
[set someOutput IGFActRef.someOutputVar] | |||
LOCAL STATIC FUNCTIONS | |||
This is the same principle but the object is an item (something you can carry) and therefore movable, e.g. a gold coin. The idea is that you move it to the player location so it's GameMode/MenuMode blocks are also active. The item must be a persistant object and (initially) disabled so it is invisible when near the player. | |||
The call syntax is slightly different: | |||
[set IGFLActRef.someInputVar to someInput] | |||
set IGFLActRef.enabled to 1 | |||
IGFLActRef.MoveTo player | |||
In this case you are enabling the GameMode/MenuMode block by bringing the object to you. However, you may need to deactivate it sometime later or otherwise make a safety switch to prevent it functioning when you dont expect it to. | |||
You can have the item script do most of the work and instead call the activate method to do the equivalent of a ScriptEffectStart block for spells - the GameMode block being equivalent to the ScriptEffectUpdate block. | |||
[set IGFActRef.someInputVar to someInput] | |||
IGFActRef.Activate player 1 | |||
IGFLActRef.MoveTo player | |||
[set someOutput IGFActRef.someOutputVar] | |||
USEFUL EXAMPLE IGF | |||
Here is an example of a method that you can call to get the position of the target cross hairs and the direction the player is looking: | |||
scn TargFunctionScript | scn TargFunctionScript | ||
Line 87: | Line 119: | ||
NOTES | |||
1. Best to always use the '1' flag when you use the Activate command. This prevents any default activation method being triggered, e.g. ending up in your inventory for item IGFs. For static activators this isn't so important but mixing up Activate commands w/ and w/o the '1' flag can lead to 'wierd' effects. | |||
2. Do not try to make too many calls to the same activator in the same frame. There appears to be some kind of recursion catch that stops calls working if the same script is called within the same frame more than ~4 times. (A similar thing happens if you do PlaceAtMe for scripted objects.) | |||
3. Quest Stage Functions: Apart from being useful in their own right, these have one nice feature that IGFs do not: a call funcion-by-number utility, i.e. | |||
set x to 10; any value between 0-255 | set x to 10; any value between 0-255 | ||
SetStage MyQuest x | SetStage MyQuest x | ||
This | This may be used to create small linked-lists, stacks, arrays, random effects, etc. | ||
[[Category: Useful Code]] | [[Category: Useful Code]] |