This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ~ ~ NOTOC~ ~ Scripting: Events Skyline is an event driven system and as so provides many event messages for you to use to communicate with other objects or to process the controls your end user is activating. E.g. KeyDown event, Damage Event, Timer event, Game State event etc. Please see the online Skyline Lua API Events section for a comprehensive list of available events. https://api.aurasoft-skyline.co.uk/class_basic___events.html <grid> <col sm="6"> How to Use Events Events in lua are used as a functions in your script, some pass arguments such a value or ID others do not. These functions are triggered as a response to various engine features or user defined events from script or graph. <well size="sm"> For example, when the player presses a key on the keyboard the system generates a "Key Down" event. This trigger response calls through to a Lua script by calling a function named onKeyDown(keyPressed). The "keyPressed" variable in the argument will be the key letter/number that the user pressed. To use this event just add the function to your script: function onKeyDown( key ) sky.lprint("Key Pressed: "..key); -- Do something here end Now any time a player presses a key, this function will be called in as many scripts that contain it. All of Skylines Events work in this way, to receive an event just add its function. Some events only become available it an specific action is attach such as with the Damage Action. This action calls the function ds_onDamage( health, damage, attackingID ) when health is lost. </well></col> <col sm="6"> Why use postInit()? A bit of advice for when setting up variables at the start of your game. The onInit() Event is called when an object is initialized in the scene. There are times when you may want to access other objects data, such as the players ID. You would think that the onInit() would be a good place to do some variable setup. <well size="sm"> For example if our object wanted to know what the players ID was. playerID = entity.getIDFromTag("Player"); But imagine if a player was added to the scene after this object, our current object would not know that the player exists, but you will still be trying to get its ID. In this case we would get playerID = -1 not what we are looking for. As you can imagine this could cause a bug in your game! To get around this we use the function postInit() function postInit() -- Set up Vars playerID = entity.getIDFromTag("Player"); end This postInit() Event is called once all of the scenes objects have been initialized. So now if you call for the Players ID it will definitely exist? </well> </col></grid> <-manual_scripting:manual_scripting_scenescript|Previous: Scene Script^manual_scripting:manual_scripting_index|Scripting Index^manual_scripting:manual_scripting_communication_tags_ids|Next: Tags and ID'sā Detach Close Document TOC Developer Sidebar SidebarDev HTML5 Bootstrap Commands Nav Menu Example TOC Ideas Site Index Layout: Tutorial Intro Layout: Tutorial Page Layout: FAQ Page Layout: Index Home Welcome What is Skyline Terminology FAQ FAQ Index Working on Scenes Scripting Assets General Info Installation and Setup Game Objects Manual Scripting Index Script Overview Micro Scripts External Scripts Scene Scripts Events Tags and ID's Communicating with Scripts Communicating with Modules Communicating with actions Dynamic Properties Learning Tutorials Index Basic Character Basic Shooting Guides Index Getting Started Video Tutorials Index