Denizen/Commands/Flag

From Citizens Wiki

< Denizen‎ | Commands

Revision as of 16:57, 7 July 2013 by Morphan1 (talk | contribs)

Introduction

Flags are variables that can be checked anywhere in a script and in other scripts by using flag replaceable tags or the flagged requirement. A flag can be placed on the player, the NPC or globally. Flags placed on a player only apply to that player, and flags placed on an NPC only apply to that individual NPC based on its ID, so NPCs with the same name have different flags because they have different IDs. However, a global flag applies to the entire server and can easily be read from any script.

Once you set a flag, you can call it back at any time with one of the replaceable tags.

Usage

To begin, you need to actually set a flag. You can do this by using

- flag ({player}|npc|global) [name([#])](:action)[:value] (duration:#)

If a flag's type (player, npc or global) is not specified, the flag is placed on the player by default, and if a value for the flag is not specified, the value is "true" by default.

...Too much for you? Let's slow it down.

The Basics

To start using flags, you must first understand the basics. This means learning the 4 types of flags you can use: booleans, strings, integers, and lists.

Boolean

The first, most used, most basic flag you need (besides a default flag) is a boolean flag. A boolean is a variable that represents either true or false.

You can set a boolean flag to true by using

- flag "RandomFlag"

...That's it. That automatically sets the flag named RandomFlag attached to the player interacting with the script as 'true'. You can set it to false by simply doing

- flag "RandomFlag:false"

This type of flag is helpful for 'if' statements. More information on that can be found here.

String

Let's move forward. Probably the second most important flag you'll need on your journey is the string flag. Strings are variables that represent words or phrases that you can change at any time.

For example,

- flag "RandomFlag:Blah something whatever"

would set the flag 'RandomFlag' on the player who's interacting with the script as 'Blah something whatever'.

Remember, you can also attach the flag to the NPC that the script is being run by, or the server itself by specifying 'npc' or 'global'. That will be covered in the advanced section.

Integer