VoidExpanse/scope-actions: Difference between revisions

From AtomicTorchWiki
(Created page with "= Config actions = Used to work with events, such as triggers and events. More info about events in VoidExpanse/events. '''Visibility:''' Global. == List of functions ==...")
 
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Config actions =
<noinclude>
[[Category:VoidExpanse/api_scopes]]
</noinclude>
 
= Scope actions =
Used to work with events, such as triggers and events.
Used to work with events, such as triggers and events.
More info about events in [[VoidExpanse/events]].
More info about events in [[VoidExpanse/events|Events]].


'''Visibility:''' Global.
'''Visibility:''' Global.
Line 10: Line 14:
* string: event_name
* string: event_name
* string: function_name|
* string: function_name|
bool - returns whether function was hooked to event, or not (due to some errors)|
void|
<nowiki>actions.Bind("OnShipDestroyed", "OnShipDestroyedHandler");</nowiki> |
<pre style="margin:0px">actions.Bind("OnShipDestroyed", "OnShipDestroyedHandler");</pre> |
Binds script's function to some in-game event. This function will be called every time event
Binds script's function to some in-game event. This function will be called every time event
occurs, for example, if function was bound to "OnShipDestroyed" event, it'll be called every time
occurs, for example, if function was bound to "OnShipDestroyed" event, it'll be called every time
Line 19: Line 23:
}}
}}


{{Scripting_api|Create|
* string: event_name|
void|
<pre style="margin:0px">actions.Create("MyEvent");</pre> |
Creates custom event, to which other scripts can bind their functions. Later can be invoked using function Start (see below)
}}
{{Scripting_api|Remove|
* string: event_name|
void|
<pre style="margin:0px">actions.Remove("MyEvent");</pre> |
Removes custom event, that was created with actions.Create method.
}}
{{Scripting_api|Clear|
* string: event_name|
void|
<pre style="margin:0px">actions.Clear("OnNpcDie");</pre> |
Removes all subscriptions to specified event. Also includes subscriptions made from another scripts.
}}
{{Scripting_api|Start|
* string: event_name
* object: args|
void|
<pre style="margin:0px">actions.Start("MyEvent", {my_name: "dlirry"})</pre>|
Invokes event with specified parameters, that'll force all subscribed functions to be called.
}}


{{Scripting_api|BindToTrigger|
{{Scripting_api|BindToTrigger|
Line 25: Line 57:
* object: parameters|
* object: parameters|
void|
void|
<nowiki>topic.Bind("onNpcDie", "OnHiveKilled",
<pre style="margin:0px">topic.Bind("onNpcDie", "OnHiveKilled",
{  
{  
     tags_class: "alien_hive",
     tags_class: "alien_hive",
     killer_ship_id: topic.GetCurrentShipId()
     killer_ship_id: topic.GetCurrentShipId()
});</nowiki> |
});</pre>|
Binds script's function to specific trigger (triggers are almost the same as events, but
<nowiki>Binds script's function to specific trigger (triggers are almost the same as events, but
they also can have parameters, that'll be filtered on C# level, thus making script to work faster).
they also can have parameters, that'll be filtered on C# level, thus making script to work faster).
Parameters, specified as third argument, must furfill following requirements:
Parameters, specified as third argument, must furfill following requirements:
* parameter names must be exactly the same as those, with which trigger is invoked
* parameter names must be exactly the same as those, with which trigger is invoked
* parameter can also use special forms, like this one: we can filter all npc-related triggers also by npc's tags, like this: tags_VARNAME_IN_TAGS. Like it was done in an example above - function will be called only when npc with tags.class == "alien_hive" is killed.
* parameter can also use special forms, like this one: we can filter all npc-related triggers also by npc's tags, like this: tags_VARNAME_IN_TAGS. Like it was done in an example above - function will be called only when npc with tags.class == "alien_hive" is killed.</nowiki>
}}
 
{{Scripting_api|Clear|
* string: event_name|
void|
<nowiki>actions.Clear("OnNpcDie");</nowiki> |
Removes all subscriptions to specified event. Also includes subscriptions made from another scripts.
}}
 
{{Scripting_api|Create|
* string: event_name|
void|
<nowiki>actions.Create("MyEvent");</nowiki> |
Creates custom event, to which other scripts can bind their functions. Later can be invoked using function Start (see below)
}}
}}


{{Scripting_api|InvokeTrigger|
{{Scripting_api|InvokeTrigger|
Line 56: Line 73:
* object: args |
* object: args |
void|
void|
<nowiki>actions.InvokeTrigger("onSystemLiberated", {system_id: sys_id});</nowiki> |
<pre style="margin:0px">actions.InvokeTrigger("onSystemLiberated", {system_id: sys_id});</pre> |
Invokes trigger with parameters. As trigger name you can use any string you like, if no one
Invokes trigger with parameters. As trigger name you can use any string you like, if no one
was subscribed to this trigger - it'll simply be ignored. The same goes to parameters.
was subscribed to this trigger - it'll simply be ignored. The same goes to parameters.
}}
{{Scripting_api|Remove|
* string: event_name|
void|
<nowiki>actions.Remove("MyEvent");</nowiki> |
Removes custom event, that was created with actions.Create method.
}}
{{Scripting_api|Start|
* string: event_name
* object: args|
void|
<nowiki>actions.Start("MyEvent", {my_name: "dlirry"})</nowiki> |
Invokes event with specified parameters, that'll force all subscribed functions to be called.
}}
}}


Line 82: Line 82:
* string: function_name|
* string: function_name|
void|
void|
<nowiki>actions.UnbindFromTrigger("myTrigger", "MyTriggerHandler")</nowiki> |
<pre style="margin:0px">actions.UnbindFromTrigger("myTrigger", "MyTriggerHandler")</pre> |
Unbinds specified function from trigger.
Unbinds specified function from trigger.
}}
}}
Line 89: Line 89:
void|
void|
void|
void|
<nowiki>actions.UnbindFromTriggers();</nowiki> |
<pre style="margin:0px">actions.UnbindFromTriggers();</pre> |
Unbinds all script's function from triggers. Useful, when you want to destroy script or do not want to use it anymore,
Unbinds all script's function from triggers. Useful, when you want to destroy script or do not want to use it anymore,
and you want to quickly get rid of all script's trigger dependencies and subscriptions.
and you want to quickly get rid of all script's trigger dependencies and subscriptions.
}}
}}

Latest revision as of 10:37, 14 February 2014


Scope actions

Used to work with events, such as triggers and events. More info about events in Events.

Visibility: Global.

List of functions

Bind
Arguments Returns Example
  • string: event_name
  • string: function_name

void

actions.Bind("OnShipDestroyed", "OnShipDestroyedHandler");
Description

Binds script's function to some in-game event. This function will be called every time event occurs, for example, if function was bound to "OnShipDestroyed" event, it'll be called every time any ship is destroyed. Note: you can bind not only to standard events, but also to events you've created. To know, how to create your own event, look into Create & Start functions of actions scope.


Create
Arguments Returns Example
  • string: event_name

void

actions.Create("MyEvent");
Description

Creates custom event, to which other scripts can bind their functions. Later can be invoked using function Start (see below)


Remove
Arguments Returns Example
  • string: event_name

void

actions.Remove("MyEvent");
Description

Removes custom event, that was created with actions.Create method.


Clear
Arguments Returns Example
  • string: event_name

void

actions.Clear("OnNpcDie");
Description

Removes all subscriptions to specified event. Also includes subscriptions made from another scripts.


Start
Arguments Returns Example
  • string: event_name
  • object: args

void

actions.Start("MyEvent", {my_name: "dlirry"})
Description

Invokes event with specified parameters, that'll force all subscribed functions to be called.


BindToTrigger
Arguments Returns Example
  • string: trigger_name
  • string: function_name
  • object: parameters

void

topic.Bind("onNpcDie", "OnHiveKilled",
{ 
     tags_class: "alien_hive",
     killer_ship_id: topic.GetCurrentShipId()
});
Description

Binds script's function to specific trigger (triggers are almost the same as events, but they also can have parameters, that'll be filtered on C# level, thus making script to work faster). Parameters, specified as third argument, must furfill following requirements: * parameter names must be exactly the same as those, with which trigger is invoked * parameter can also use special forms, like this one: we can filter all npc-related triggers also by npc's tags, like this: tags_VARNAME_IN_TAGS. Like it was done in an example above - function will be called only when npc with tags.class == "alien_hive" is killed.


InvokeTrigger
Arguments Returns Example
  • string: trigger_name
  • object: args

void

actions.InvokeTrigger("onSystemLiberated", {system_id: sys_id});
Description

Invokes trigger with parameters. As trigger name you can use any string you like, if no one was subscribed to this trigger - it'll simply be ignored. The same goes to parameters.


UnbindFromTrigger
Arguments Returns Example
  • string: trigger_name
  • string: function_name

void

actions.UnbindFromTrigger("myTrigger", "MyTriggerHandler")
Description

Unbinds specified function from trigger.


UnbindFromTriggers
Arguments Returns Example

void

void

actions.UnbindFromTriggers();
Description

Unbinds all script's function from triggers. Useful, when you want to destroy script or do not want to use it anymore, and you want to quickly get rid of all script's trigger dependencies and subscriptions.