-How would I make it so that once you've trigged a dialog option (and any connected scripts), you don't get the dialog option again? I get the feeling this has to do with globals/booleans, which I've never really understood.
You'd usually use either local or global variables for this.
Local variables are stored on a particular object (like a creature, placeable, trigger, area or module) and can only be accessed when that object is present in the active game world (i.e. exists in the same module as the player currently is in). There are a fixed number of available local variable slots for each object.
In TSL there are 160 boolean slots (numbered 0-159) and 32 number slots (numbered 0-31) for each object. A boolean variable is like an on/off switch and can only contain either the value FALSE (0) or not FALSE (true). A number variable can contain a value between 0 and 255.
Note: As far as I can tell you can't reliably set local variables on inventory items (weapons, robes, armbands etc).
Global variables can be accessed from anywhere in the game and are not set for a particular object. Unlike local variables they are accessed by a text tag/name instead of a slot number, and they must be added to the globalcat.2da file for the game to recognize them.
Which type you choose to use is generally up to you, but just tracking dialog stages of a single NPC is often best to set as either a local number variable, or a series of local boolean variables, on that NPC, since the info is only needed by that NPC thus reducing the amount of global data the game need to keep track of, and you won't have to modify any 2DA files for them to work.
For things like plot progress, quests and the like you usually use global variables, since those can be checked from anywhere and aren't associated with one particular NPC or object.
In TSL there are a number of ready-made scripts you can use to set and check both global and local variables in dialogs.
Setting:
a_global_dec - decreases the global number variable whose tag is set in the String Param field by the number set in the P1 field.
a_global_inc - increases the global number variable whose tag is set in the String Param field by the number set in the P1 field.
a_global_set - sets the global number variable whose tag is set in the String Param field to the number set in the P1 field.
a_global_bool_set - sets the global boolean variable whose tag is set in the String Param field to the value set in the P1 field. ( 0 = false, 1 = true )
a_localn_dec - decreases the local number variable on the object whose tag is set in the String Param field, and whose slot index is set by the P1 parameter, by the number set in the P2 field. (leave the String Param field blank to use the object running the script = the conversation owner)
a_localn_inc - increases the local number variable on the object whose tag is set in the String Param field, and whose slot index is set by the P1 parameter, by the number set in the P2 field. (leave the String Param field blank to use the object running the script = the conversation owner)
a_localn_set - sets the local number variable on the object whose tag is set in the String Param field, and whose slot index is set by the P1 parameter, to the number set in the P2 field. (leave the String Param field blank to use the object running the script = the conversation owner)
a_local_set - sets the local boolean variable on the object whose tag is set in the String Param field, and whose slot index is set by the P1 parameter. (leave the String Param field blank to use the object running the script = the conversation owner)
Getting:
c_global_eq - returns true if the global number specified by the String Param field equals the number set in the P1 field.
c_global_gt - returns true if the global number specified by the String Param field is greater than the number set in the P1 field.
c_global_lt - returns true if the global number specified by the String Param field is lower than the number set in the P1 field.
c_global_bet - returns true if the global number specified by the String Param field is higher than the number set in the P1 field and lower than the number set in the P2 field.
c_global_set - returns true if the global boolean specified by the String Param field is set (true).
c_localn_eq - returns true if the local number set on the object whose tag is set in the String Param field (leave blank for conversation owner), where the slot index is set in the P1 field, matches the value in the P2 field.
c_localn_gt - returns true if the local number set on the object whose tag is set in the String Param field (leave blank for conversation owner), where the slot index is set in the P1 field, is greater than the value in the P2 field.
c_localn_lt - returns true if the local number set on the object whose tag is set in the String Param field (leave blank for conversation owner), where the slot index is set in the P1 field, is lower than the value in the P2 field.
c_local_set - returns true if the local boolean set on the object whose tag is set in the String Param field (leave blank for conversation owner), where the slot index is set in the P1 field, is true (i.e. not FALSE).
c_local_notset - returns true if the local boolean set on the object whose tag is set in the String Param field (leave blank for conversation owner), where the slot index is set in the P1 field, is FALSE (0).
P1, P2 and String Param above refer to the input fields listed to the right of the script name field in tk102's DLG Editor.
Some local numbers and booleans are already used by generic scripts such as the Random Loot and AI scripts, and as such should be avoided for any objects of that type that have AI scripts/loot scripts. Here is a likely incomplete list of some locals already used:
Creatures:
Boolean 1-3 - Creature AI, ambient NPC settings.
Boolean 10 - Dialogs, used to set that the creature has been talked to once.
Boolean 20-28 - Creature AI, used to activate userdefined script events.
Boolean 29 - Creature AI, used to set if NPC should play ambient animations when idle.
Boolean 30-64 - Reserved range for scenario/plot specific uses, some NPCs use them, most do not.
Boolean 65 - Creature AI, used to set of the NPC should walk around randomly when idle.
Boolean 66-86 - Creature AI, various settings set in the NPC spawn scripts.
Boolean 87 - Creature AI, blocks out the AI for this creature if set.
Boolean 88 - Creature AI defined, but likely unused in K2:TSL.
Boolean 89 - Creature AI, sets the creature to use the Boss Combat AI, overriding their normal AI style.
Boolean 90 - Creature AI, sets that the creature has activated their energy shield in combat.
Boolean 91 - Creature AI, toggles userdefined event for the OnDialogEnd event handler.
Boolean 92 - Creature AI, sets that a force using NPC has buffed with Resist/Immunity at start of battle.
Boolean 94 - Creature AI, sets that the creature has entered combat.
Boolean 95 - Creature AI, sets the creature to use the KotOR1 Malak end fight AI.
Boolean 96 - Creature AI, sets creature to use a zone controller to determine their combat zone.
Boolean 97 - Creature AI, setting for the OnDialog event.
Boolean 98-109 - Creature AI, used by the waypoint walking/ambient animation system.
Boolean 110-159 - Generally unused as far as I can tell.
Number 0-2 - Creature AI, used by the waypoint walking/ambient animation system.
Number 3-6 - Creature AI, internal state info for last attack used, chosen attack pattern etc.
Number 7 - Creature AI, Zone Controller this creature is attached to, if any.
Number 8-9 - Creature AI, settings for healer AI, how much to heal and how often.
Number 10-11 - Creature AI, used for turrets to determine rate of fire.
Number 12-31 - Generally unused as far as I can tell.
Placeables:
Boolean 10-19 - Security terminals, used to set the user's choice of action.
Boolean 55 - Containers, container has been bashed and broken item substituted.
Boolean 57 - Containers, used to set that random loot has been spawned.
Triggers:
Boolean 40 - Used to set that the trigger has been tripped for one-shot triggers.
For more about local variables: see this thread (
http://www.lucasforums.com/showthread.php?t=173587) ~tk