Difference between revisions of "Scripting Tutorial: My Second Script"

m
imported>DragoonWraith
(Featured!)
imported>8asrun6aer
 
(3 intermediate revisions by 2 users not shown)
Line 5: Line 5:


This tutorial is meant to be a more complete introduction to scripting for Oblivion than the My First Script tutorial, and assumes that the reader is already familiar with My First Script.  If you do not understand the main points of that tutorial, you may find yourself in over your head here.  If you're comfortable with My First Script, though, let's begin scripting!
This tutorial is meant to be a more complete introduction to scripting for Oblivion than the My First Script tutorial, and assumes that the reader is already familiar with My First Script.  If you do not understand the main points of that tutorial, you may find yourself in over your head here.  If you're comfortable with My First Script, though, let's begin scripting!
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]|opt0=[[OBSE]]}}


==More information about scripting in Oblivion==
==More information about scripting in Oblivion==
Line 68: Line 70:
   ; Here we will enter what happens when the chest is opened.
   ; Here we will enter what happens when the chest is opened.
End</pre>
End</pre>
'''Click ''Save'' again now.''' The script still doesn't do anything, but at least now we have defined under what conditions it will run.  There are a couple of things to note here.  First, we have ended the current block before beginning a new one—not so important when there's only one block, but as this script gets more complicated we'll need multiple blocks in a single script.  In somewhat more technical terms, '''Begin/End blocks do not nest.'''  The other thing to notice is the semicolon ";" on line 4.  A semicolon marks the rest of the line as ''comment''.  Whatever you type after the semicolon ''on that one line'' will be ignored when the script compiles. You use comments to explain your code, which can help you and others understand what's going on inside the script quickly at a later date.  If you want more than one line of comment, you must have one semicolon for each line.
'''Click ''Save'' again now.''' The script still doesn't do anything, but at least now we have defined under what conditions it will run.  There are a couple of things to note here.  First, we have ended the current block before beginning a new one—not so important when there's only one block, but as this script gets more complicated we'll need multiple blocks in a single script.  In somewhat more technical terms, '''Begin/End blocks do not nest.'''  The other thing to notice is the semicolon ";" on line 4.  A semicolon marks the rest of the line as ''comment''.   
 
===Code Comments===
Comments can be placed anywhere in-code with the semicolon character - ''';''' - Whatever you type ''after'' the semicolon on the same line will be ignored when the script compiles. If you want more than one line of comment, you must have one semicolon for each line.
 
You use comments inside your scripts to generally explain what you are trying to accomplish in your code, which can help you and others understand what's going on inside the script quickly at a later date.  Comments can also serve as a debugging technique by commenting out lines of code one-by-one to pinpoint the source of some odd or unintended effect in-game. 
 
Note: Because everything appearing on a line after the semicolon is not treated as compilable code, one issue you might face is that you cannot simply put semicolons in strings.  If you need to have a semicolon as part of a string - for example a message in-game - you could instead use the [[OBSE]] "%a" Format Specifier for functions that support this and passing in ASCII character code 59, or use the [[AsciiToChar]] OBSE function.


===Writing text and obtaining decisions from the player===
===Writing text and obtaining decisions from the player===
Anonymous user