A Beginner's Guide to Scripting Page 2: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
{{A Beginner's Guide to Scripting}} | {{A Beginner's Guide to Scripting}} | ||
On this page we shall begin writing scripts that can perform real tasks in your fan missions. | On this page we shall begin writing scripts that can perform real tasks in your fan missions. |
Revision as of 21:07, 10 January 2009
On this page we shall begin writing scripts that can perform real tasks in your fan missions.
- You should already understand the scripting essentials described on the previous page.
- You should have created a simple reasonably large one room map named testScripts.map as described on the previous page at Create a Test Map
- You should have created a script file named testScripts.script in the same folder as the map file as described on the previous page at Creating a Script File
How to Activate or Frob, an Entity
Activating an entity is to trigger it into action eg, from a targetting entity or by the player frobbing it.
First create a door in the test map and name it TestDoor.
From script we use the script event (command or instruction) activate. As described in the Creating a Function section on the previous page, script events need to be used with an entity. Previously we used print with the sys entity, ie sys.print. Now we use the activate script event with our door entity...
Using a Named Entity in a Map from Script
One easy way to refer to an entity in your map is to put the dollar sign $ at the front of the entity name. The script then knows it is an entity in your map. So we named the door we made TestDoor so in script we can refer to it as $TestDoor. So, just as we joined sys with print to get sys.print we join $TestDoor with activate to get $TestDoor.activate. You recall sys.print was then followed by the data in brackets - we put the text or values we wanted to print. With activate we have to put a triggering entity...
activate's Triggering Entity
The data in brackets that follows activate is a triggering entity. Where there is no particular triggering entity needed use player1 which, preceded by $ becomes $player1. So...
The Complete activate System Event
Our complete system event is thus $TestDoor.activate($player1)
WORK IN PROGRESS...............