-
Notifications
You must be signed in to change notification settings - Fork 9
A Set allows you to store a sequence of unique strings and look them up efficiently. When adding a string a Set will automatically test whether such string is already contained and won't make a duplicate.
Because of how a Set work internally, searching for a string in a Set is faster than searching for it in a plain array. Its advantage increases with the number of items. They are also fast in adding and removing items dynamically.
Similar to Dictionary
, Set has two general properties: sort style and compare style.
Sort style defines whether items are stored sorted or unsorted. The unsorted containers are typically faster to search in, but the items will be stored in an undefined order.
Compare style determines whether strings are compared as case sensitive or case insensitive. For example, in a case-sensitive Set the strings "Parameter" and "parameter" will be seen as two different items, but in a case-insensitive Set they will be seen as identical. Compare style defines both string uniqueness and sorting.
At the moment a Set does not let you directly access all of its internal data at once, but it does have the GetItemsAsArray
function that will write all items to a dynamic array, which you may parse, print, and otherwise use as you see fit. The order of items in this array will be match the order within the Set, hence if the Set was sorted the array will be sorted as well.
Compatibility: Set struct is supported by AGS 3.5.0 and later versions.
See also: Dictionary
static Set* Set.Create(SortStyle sortStyle, StringCompareStyle compareStyle)
Creates a new empty Set of the given properties. If you don't pass any options the Set is unsorted and case-insensitive. Note that you cannot change sorting style and case sensitivity later, you would have to create another Set and move values there.
- Possible values for sortStyle:
eNonSorted
,eSorted
. - Possible values for compareStyle:
eCaseInsensitive
,eCaseSensitive
.
Example:
Set* mySet = Set.Create();
bool Set.Add(String item)
Adds an item to the Set. Returns false if the Set already contained the item, otherwise returns true.
Example:
mySet.Add("item1");
bool wasAdded = mySet.Add("item1"); // wasAdded will be false
void Set.Clear()
Removes all items from the Set.
bool Set.Contains(String item)
Returns whether an item is already in a Set.
Example:
Set* mySet = Set.Create();
mySet.Add("test");
if (mySet.Contains("test")) {
Display("Test passed!");
}
String[] GetItemsAsArray()
Creates a dynamic array filled with items in same order as they are stored in the Set, set by SortStyle
when the Set is created.
Returns null if this Set is empty.
Example:
Set* mySet = Set.Create(eSorted);
mySet.Add("test");
mySet.Add("test2");
String items[] = mySet.GetItemsAsArray();
for (int i = 0; i < mySet.ItemCount; i++)
Display("#%d: %s", i, items[i]);
In the above example the items will be displayed on screen one by one, preceded by their index.
See also: Set.ItemCount
bool Set.Remove(String item)
Removes an item from the Set. Returns false if there was no such item, otherwise returns true.
StringCompareStyle Set.CompareStyle
Returns the string comparison method for this Set.
See also: SortStyle
int Set.ItemCount
Returns the number of items currently in the Set.
SortStyle Set.SortStyle
Returns the sorting method for this Set.
See also: CompareStyle
Getting Started in AGS
Editor
- New Game templates
- Editor Preferences
- General Settings
- Default Setup
- Colours Editor
- Room Editor
- Character Editor
- Cursor Editor
- Dialog Editor
- Font Preview
- GUI Editor
- Inventory Items Editor
- View Editor
- Sprite Manager
- Music and sound
- Voice speech
- Script Modules
- System limits
- Log Panel
- Plugins
- Other Features
Engine
Scripting
- Scripting Tutorial
- Scripting Language
-
Scripting API
- Script API Overview
- Standard Constants
- Standard Enumerated Types
- Standard Types
- Game variables
- Global arrays
- Global event handlers
- repeatedly_execute / repeatedly_execute_always
- Custom dialog options rendering
- Global functions: general
- Global functions: message display
- Global functions: multimedia actions
- Global functions: palette operations
- Global functions: room actions
- Global functions: screen effects
- Global functions: wait
- AudioChannel functions and properties
- AudioClip functions and properties
- Camera functions and properties
- Character functions and properties
- DateTime functions and properties
- Dialog functions and properties
- DialogOptionsRenderingInfo functions and properties
- Dictionary functions and properties
- DrawingSurface functions and properties
- DynamicSprite functions and properties
- File functions and properties
- Game functions and properties
- GUI functions and properties
- GUI control functions and properties
- GUI Button functions and properties
- GUI InvWindow functions and properties
- GUI Label functions and properties
- GUI List Box functions and properties
- GUI Slider properties
- GUI Text Box functions and properties
- Hotspot functions and properties
- Inventory item functions and properties
- Maths functions and properties
- Mouse functions and properties
- Object functions and properties
- Overlay functions and properties
- Parser functions
- Region functions and properties
- Room functions and properties
- Screen functions and properties
- Set functions and properties
- Speech functions and properties
- String functions
- System functions and properties
- TextWindowGUI functions and properties
- ViewFrame functions and properties
- Viewport functions and properties
- Obsolete Script API
- Event Types
- Key code table
- Audio in script
Legal Notice
Getting in touch
Misc