Difference between revisions of "Scripting Tutorial: Basic Scripting Knowledge"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Sythe1525
imported>Darkness X
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}}
A script is a small program that runs within the game, the Oblivion scripting language is rather simple, and experience in any other programming language brings you quite far.
A script is a small program that runs within the game, the Oblivion scripting language is rather simple, and experience in any other programming language brings you quite far.


Line 4: Line 5:


You can also comment your scripting code by using the ';' everything after the semicolon will be ignored.
You can also comment your scripting code by using the ';' everything after the semicolon will be ignored.


Scripting-Operations can be divided in two base categories, each with two sub-categories:
Scripting-Operations can be divided in two base categories, each with two sub-categories:


 
== [[:Category:Commands|Commands]] ==
== 1. [[:Category:Commands|Commands]] ==


A command is a script-operation that controls what happens within the script. Commands regulate how a script is executed, but don't affect the world directly.
A command is a script-operation that controls what happens within the script. Commands regulate how a script is executed, but don't affect the world directly.


There are two sub-categories: ''administrative commands'' and ''statements'':
There are two sub-categories: ''administrative commands'' and ''statements'':


*''Administrative Commands'' are [[Scriptname]], [[Begin]]...[[End]] and the [[:Category:Blocktypes|Blocktypes]] used by [[Begin]]. Every working script requires at a [[Scriptname]], and one [[Begin]]...[[End]] block, to assign the script to objects and control '''when''' the script is exectued.
*''Administrative Commands'' are [[Scriptname]], [[Begin]]...[[End]] and the [[:Category:Blocktypes|Blocktypes]] used by [[Begin]]. Every working script requires at least a [[Scriptname]], and one [[Begin]]...[[End]] block, to assign the script to objects and control '''when''' the script is exectued.


*''Statements'' are [[Set]], [[If]], [[Return]] and the [[Declaring_variables|variable declarations]] Statements aren't required for a script to work, but all but the most simple scripts require them to control '''how''' the script is executed.  
*''Statements'' are [[Set]], [[If]], [[Return]] and the [[Declaring_variables|variable declarations]] Statements aren't required for a script to work, but all but the most simple scripts require them to control '''how''' the script is executed.  


<br>
== [[:Category:Functions|Functions]] ==
 
== 2. [[:Category:Functions|Functions]] ==


Functions are script operations that interact with the game-world. This is by far the larger category of script operations. Every function returns a value which can be used as condition for [[If|"if"-Statements]] or to set variables with the [[Set|"set"-statement]].
Functions are script operations that interact with the game-world. This is by far the larger category of script operations. Every function returns a value which can be used as condition for [[If|"if"-Statements]] or to set variables with the [[Set|"set"-statement]].


There are two sub categories: ''passive'' and ''active'' functions:
There are two sub categories: ''passive'' and ''active'' functions:
Line 33: Line 28:
*''Active functions'' do changes to the game-world and usually return a boolean value ("1" or "0") to return if the action was successful or not. [[RemoveSpell]] for example removes a spell from the target and returns "1" if this was successful (i.e. the target had the spell in the first place). [[PlaceAtMe]] creates an object at the caller's location and returns the Reference to this object.
*''Active functions'' do changes to the game-world and usually return a boolean value ("1" or "0") to return if the action was successful or not. [[RemoveSpell]] for example removes a spell from the target and returns "1" if this was successful (i.e. the target had the spell in the first place). [[PlaceAtMe]] creates an object at the caller's location and returns the Reference to this object.


<br>
==[[Reference|References]] and [[:Category:Variables|Variables]] ==
== 3. [[:Category:References|References]] and [[:Category:Variables|Variables]] ==


Functions affect the "calling object" (That on which the script is running) by default, but you can redirect them to another object by using the object's [[:Category:References|reference]]. When you want a script to affect the player for example, use the player's reference ("Player") and a '.' to redirect the function-call to the player instead of the calling object.
Functions affect the "calling object" (That on which the script is running) by default, but you can redirect them to another object by using the object's [[Reference|reference]]. When you want a script to affect the player for example, use the player's reference ("Player") and a '.' to redirect the function-call to the player instead of the calling object.


  player.additem gold_001 100
  player.additem gold_001 100


To gain more flexibility, you can use [[:Category:Variables|variables]] instead of numeric values whenever a function requires such input.
To gain more flexibility, you can use [[:Category:Variables|variables]] instead of numeric values whenever a function requires such input.

Latest revision as of 10:41, 15 April 2010

Tools used in this tutorial

Required


A script is a small program that runs within the game, the Oblivion scripting language is rather simple, and experience in any other programming language brings you quite far.

As a general rule: every operation needs to be put in a new line.

You can also comment your scripting code by using the ';' everything after the semicolon will be ignored.

Scripting-Operations can be divided in two base categories, each with two sub-categories:

Commands[edit | edit source]

A command is a script-operation that controls what happens within the script. Commands regulate how a script is executed, but don't affect the world directly.

There are two sub-categories: administrative commands and statements:

  • Statements are Set, If, Return and the variable declarations Statements aren't required for a script to work, but all but the most simple scripts require them to control how the script is executed.

Functions[edit | edit source]

Functions are script operations that interact with the game-world. This is by far the larger category of script operations. Every function returns a value which can be used as condition for "if"-Statements or to set variables with the "set"-statement.

There are two sub categories: passive and active functions:

  • Passive functions check out for certain states within the game and return a numeric value that represents them. Examples are GetActorValue, which returns a concrete value or GetDetected which returns "1" if the target is detected and "0" when not.
  • Active functions do changes to the game-world and usually return a boolean value ("1" or "0") to return if the action was successful or not. RemoveSpell for example removes a spell from the target and returns "1" if this was successful (i.e. the target had the spell in the first place). PlaceAtMe creates an object at the caller's location and returns the Reference to this object.

References and Variables[edit | edit source]

Functions affect the "calling object" (That on which the script is running) by default, but you can redirect them to another object by using the object's reference. When you want a script to affect the player for example, use the player's reference ("Player") and a '.' to redirect the function-call to the player instead of the calling object.

player.additem gold_001 100

To gain more flexibility, you can use variables instead of numeric values whenever a function requires such input.

short addgold
set addgold to 100
player.additem gold_001 addgold

You can only use variables in the same script or global variables, though. It is not possible to refer to a local variable of another script within a function. Only the If and Set commands can access such redirected variables.

player.additem gold_001 otherobject.addgold

This will not work, you need to use this instead:

short addgold
set addgold to otherobject.addgold
player.additem gold_001 addgold