![]() |
![]() |
|||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Setting Variables Intended Audience: [Printer Friendly / Syntax Highlight]
The most common command you will use when setting variables is this: void SetLocalInt(object oObject, string sVarName, int nValue) This command sets a 'local integer'. What does it mean by local? It means that the integer is referenced to, or 'stored on', the oObject you specify (it isn't really stored there physically, but it's easier to think of it that way). There are three things that are important to remember, here: - the 'oObject' has to be a valid object. You will see many commands that return object at the beginning of their structure (like it says 'void' at the beginning of SetLocalInt). This means that those commands return data of the type object. - the 'string sVarName' is the name you give to your variable. Make sure it is unique. Like all strings, it must be enclosed in quotes (like "VARIABLE1" above). Variable names are not case-sensitive. - the 'int nValue' is the information you're storing in the variable. Since it is an integer we're setting with this command, it must be a number (with no decimal places)... such as 1, 15 or 320. If you wanted to store different information here, you need a different command: SetLocalFloat = stores a float number (a number with a decimal place) How do I use variables? If I wanted to recall that integer data I just set in a variable, I would use this: int GetLocalInt(object oObject, string sVarName) This is exactly the same command as what you just used to set the variable... minus the actual value of the data (as that's what you're looking for). Note that this isn't a void command... it returns an integer, actual information. This means you don't just use this command on its own. You use it to define either needed 'int' data in another command or a variable you are setting... like so: int nValue = GetLocalInt(OBJECT_SELF, "VARIABLE1"); The above means you have just specified a new variable called 'nValue' which is now equal to the integer that was stored in the OBJECT_SELF under the name of "VARIABLE1". Confused yet? Examples... One great example of how a variable might be used is to track the progression of plots. Let's say I want to have a variable called "STORY"... when the player accepts the plot, I set it to 1. When the player finishes the plot, I set it to 2. The player accepted the plot... The player finishes the plot... How do I know if the player has accepted or finished the plot or not? When it comes to dialogue, you just need to make a new starting node for each condition. The computer will start from the top and check any scripts in the 'Text Appears When' section and see if it is TRUE (or if there is no script there, which makes it automatically TRUE). If so, it starts that node. If not, it continues to the next. So, with this plot, you'd list the nodes from last to first... #1. (plot done) "Thank you for doing that plot." So you need a script which returns TRUE for #1 if the PC has the "STORY" variable on him set to 2, right? And for #2, the script must return TRUE if the variable is set to 1. No script is needed for 3, because if both #1 and #2 were FALSE, then the plot has neither been accepted nor done. Is the plot done? Is the plot accepted? So you'd end up with this: #1. (1st script in "Text Appears When") "Thank you for doing that plot." In the above script, I only want the NPC to give the plot to 1 person. At the point when he sets the "STORY" variable on the PC to 1, why not have him set a variable called "PLOT_GIVEN" to 1 on OBJECT_SELF (the NPC)? Then when the dialogue branches from the default #3 dialogue (because another PC with no "STORY" variable on him wanders along and speaks to the NPC), you could have the dialogue split into two: |
A REALLY SIMPLE EXAMPLE QUEST DIALOGUE The thing to remember is that when you line up your 'starting nodes' underneath the Root, they should be in reverse order of completion. Let's say your NPC gave three jobs. Imagine the following structure under the root: #1. "I don't have any more jobs for you." The thing to remember is that when the NPC is clicked on for dialogue, the computer will begin scanning the scripts in the 'Text Appears When' part of these nodes. If the script returns TRUE (or there is no script), that node is initiated. If it returns FALSE, it continues onto the next node. The following is a rundown of what scripts would be at each node: #1 - script in 'Text Appears When' set to return TRUE if "Job" variable on PC set to 4 like so: int StartingConditional() #2 - script in 'Text Appears When' set to return TRUE if "Job" variable on PC set to 3 (set below). If the PC has finished the job, have NPC give reward and set "Job" variable to 4 (no more jobs) in 'Actions Taken' like so: void main() #3 - script in 'Text Appears When' set to return TRUE if "Job" variable on PC set to 2 (set below). If the PC has finished the job, have NPC give reward and job #3... set "Job" variable to 3 in 'Actions Taken'. #4 - script in 'Text Appears When' set to return TRUE if "Job" variable on PC set to 1 (set below). If the PC has finished the job, have NPC give reward and job #2... set "Job" variable to 2 in 'Actions Taken'. #5 - Script in 'Text Appears When' returns TRUE if "TalkedToJoe" variable on the PC set to 1 (set below). In the dialogue, if the PC accepts job#1, set the "Job" variable on the PC to 1 in 'Actions Taken'. #6 - no script in 'Text Appears When' (if all other scripts above are FALSE, this is the first time the PC has spoken to this NPC). On the first line, put a script in 'Actions Taken' that sets a "TalkedToJoe" variable on the PC to 1. So this is the basic setting and getting of variables. Storing and using string and object data and other sorts is a little more complicated... but something that is easily caught onto once you get used to manipulating integers. Hopefully this will get you started.
|
|||||||||||||||||||||||
|
|
||
|
Multiplayer Games at Neverwinter Connections
|
||
|
Download Modules
|
||
|
5,047,702 utenti BioWare:
|
||