Difference between revisions of "Papyrus Introduction"

Jump to navigation Jump to search
2,193 bytes added ,  02:21, 11 February 2012
Additions on the notion of considering a script an Object.
imported>Starry
m (Game.GetPlayer() returns Actor and Kill() is on Actor, not ObjectReference.)
imported>ZeroMemory
(Additions on the notion of considering a script an Object.)
Line 11: Line 11:


Each script is defined to be a type of '''[[:Category:Script_Objects|Object]]''', such as a “[[Quest]]”, a “[[Reference]],” an “[[Actor]],” or a “[[Book]].” For the most part, these script objects correlate exactly to the objects found in the editor's masterfile.
Each script is defined to be a type of '''[[:Category:Script_Objects|Object]]''', such as a “[[Quest]]”, a “[[Reference]],” an “[[Actor]],” or a “[[Book]].” For the most part, these script objects correlate exactly to the objects found in the editor's masterfile.
Scripts being called '''[[:Category:Script_Objects|Objects]]''' might be confusing to some people. Scripts are added to objects in the game, they describe their behaviour and functionality. They are the "soul" of a static mesh made out of triangles and covered with a few textures which make it '''look real'''. Papyrus scripts are what makes it '''real'''. What makes it a true, "full" '''object'''.
Strictly speaking, a script is not really an object, rather an important part of it. Usually, an object has to be '''encapsulated''', contained in a single unit which might '''inherit''' some functionality from a parent class which is a more '''abstract''' or '''general''', if you will, version of it. This concept is easily employed natively in code, without a scripting language, where everything from "look" to behaviour is defined by one single, coherent, encapsulated unit of code which correlates to other units of code. "True objects" in the game are actually those which are responsible for showing the mesh on the screen (native code added on top of the Creation Engine), they encapsulate basic properties. Scripts are appended to these objects to give game designers a simple, versatile tool of defining their behaviour without going into battle with low level mechanisms that impede creativity and productivity. They extend the base object by adding behaviour to it or modifying its basic properties (eg. initiating animations in response to an event), they are not an object in their own right. They modify an object or add to it, sometimes they contain most of the object's definition. But they are not '''the object'''. That's why it's been emphasized that they correlate exactly '''for the most part''' to objects found in the editor's masterfile.
Since they add functionality to base objects they are appended to and employ object oriented paradigms like inheritance, abstraction and encapsulation (through the use of '''properties''' which, among other things, serve as a getter/setter mechanism), they can be considered as objects, as long as you keep the former in mind. '''They are the strings behind the puppets, together they make a sufficient whole. An object.'''


These objects have '''[[Function Reference|Functions]]''' that can be used to get at the data they have in them from the masterfile or that is saved in them at run time. For example, you can use the function [[GetActorValue_-_Actor|GetActorValue(“Health”)]] to get the current health value of an actor, and [[ModActorValue_-_Actor|ModActorValue(“Health”, 50)]] to add 50 points to an actor’s health value. You could also use the function [[Kill - Actor|Kill()]] to kill an actor. Each of these functions is part of the [[Actor Script]] object. If you tried to call Kill() on a [[Book Script]], because the Book script has no Kill() function defined for it (''since the game code has no notion of killing books''), the compiler will complain and refuse to compile the script, giving you an error message that Kill() is not a function on the Book script.
These objects have '''[[Function Reference|Functions]]''' that can be used to get at the data they have in them from the masterfile or that is saved in them at run time. For example, you can use the function [[GetActorValue_-_Actor|GetActorValue(“Health”)]] to get the current health value of an actor, and [[ModActorValue_-_Actor|ModActorValue(“Health”, 50)]] to add 50 points to an actor’s health value. You could also use the function [[Kill - Actor|Kill()]] to kill an actor. Each of these functions is part of the [[Actor Script]] object. If you tried to call Kill() on a [[Book Script]], because the Book script has no Kill() function defined for it (''since the game code has no notion of killing books''), the compiler will complain and refuse to compile the script, giving you an error message that Kill() is not a function on the Book script.
Anonymous user

Navigation menu