This is the fundamental problem with normal arrays.
It really sucks when for example, you need to keep track of the points at which some spells are cast. If you use normal arrays, then you have to create an array of points with a size of say, 100. This however, is not the best way to keep track of these points in terms of performance. Plus, what if there are more than 100 spells being cast simultaneously?
Have you also ever wanted to create a scoreboard where the highest scores come first? Sure, you could always open up Ctrl+Shift+L and look under Built-in > Templates and check out the sorting algorithms there, but isn't it a little troublesome and messy to have to copy from there all the time?
To save you all the hassle, I have created a library with Improved Arrays.
Benefits of using Improved Arrays
Improved Arrays are flexible like in JavaScript, or even PHP - you can freely set any value in the array and the array size is modified.
In addition to fundamental functions such as Create, Length, Exists, Type, Set, Get, Push, there are many more features such as Split String into Array, Join Array into String, Search Array Value, Index of Greatest/Lowest value in Array, Delete Array Key, Move Array Value, Swap Array Values, Reverse Array, Sort Array, Shuffle Array, Merge Arrays and so on!
Has support for both GUI and Galaxy code
Built-in and convenient looping function
A single array can store different types of array values, so you can have an array of Unit and Ability Command values or something like that (though not encouraged)
If you are experienced with the editor and understand the library's code, you can make some functions of your own too!
Current Support
Improved Arrays are made with Data Tables and supports both GUI and Galaxy users.
This set of code results in the array having the values: [2, 4, 7, 8, 10, 12]
Get Array Value
Returns the array value of a specified index of an existing array. There are various "get" actions based on the type of array value you are trying to get.
Type: Function
Parameter(s): Array Name (string), Array Index (integer)
GUI:
Get Array Value (Integer)
Get Array Value (Real)
Get Array Value (Ability Command)
Get Array Value (Boolean)
Get Array Value (Point)
Get Array Value (Region)
Get Array Value (String)
Get Array Value (Unit)
Get Array Value (Unit Group)
Galaxy:
GetInt
GetFixed
GetAbilCmd
GetBool
GetPoint
GetRegion
GetString
GetUnit
GetUnitGroup
Length of Array
Returns an integer of the number of elements (the size) of an existing array.
To use the library in your map, follow these steps:
Find the "Mods" folder in the StarCraft II folder (e.g. C:\Program Files (x86)\StarCraft II\Mods)
Put the downloaded mod "ImprovedArrays.SC2Mod" in there
In your map in SC2Editor, go to File > Dependencies > Add Other, then select ImprovedArrays.SC2Mod
If you cannot find ImprovedArrays.SC2Mod in that box, try changing the "Directory" from the dropdownlist in that dialog box, or restart the editor
Changelog
Version 1.0 (Apr 17) : initial release
Version 1.1 (Apr 18) : library is now better organised and imported as a dependency in order to retain all the grammar/hint texts
Overview
Any questions / suggestions / feedback / bug report? Also note that this library is still under development and I will update it with new features (based on YOUR suggestions) soon.
Why are there only 9 types supported? I need triggers, dialogs dialog items.
Triggers are Strings (I believe), dialogs and dialog items are integers.
You can write your own conversion functions in GUI via just adding a return action into the function and writing lp_parameterName (= paremter's ID) into its custom code. That references the parameter and the code works, if the file types match. So, e.g. your function's paremter is named "val", then you write lp_val into the return action's custom script section.
I wasn't able to write my own conversion function (there already is a function to convert a trigger to a string, called "Trigger Function Name", but when I try to write a function that reverses that process like you described, I get an "implicit cast not allowed" compile error), but I was able to copy 'n' paste existing functions and change them to use triggers. I did the same for dialogs & dialog items.
If you want an array that can be dynamically manipulated to change in size with many useful built-in functions, this trigger library is for you!
Contents
Arrays' sizes cannot change
This is the fundamental problem with normal arrays.
It really sucks when for example, you need to keep track of the points at which some spells are cast. If you use normal arrays, then you have to create an array of points with a size of say, 100. This however, is not the best way to keep track of these points in terms of performance. Plus, what if there are more than 100 spells being cast simultaneously?
Have you also ever wanted to create a scoreboard where the highest scores come first? Sure, you could always open up Ctrl+Shift+L and look under Built-in > Templates and check out the sorting algorithms there, but isn't it a little troublesome and messy to have to copy from there all the time?
To save you all the hassle, I have created a library with Improved Arrays.
Benefits of using Improved Arrays
Current Support
Improved Arrays are made with Data Tables and supports both GUI and Galaxy users.
Currently supports these types of values:
Current functions / features:
Documentation
Create Array
All arrays must be initialized before they can be used.
Example
GUI:
Galaxy:
Both sets of code initializes an array named "array_name".
Set Array Value / Push Array Value
Set and push actions can modify the values of an existing array. (Note that all arrays begin with index 0)
Set Actions
Sets the value of a particular index of an existing array. There are various "set" actions separated based on the type of array value you want to set.
GUI:
Galaxy:
Push Actions
Adds a value to the end of an existing array. There are various "push" actions separated based on the type of array value you want to push.
GUI:
Galaxy:
Example
GUI:
Galaxy:
This set of code results in the array having the values: [2, 4, 7, 8, 10, 12]
Get Array Value
Returns the array value of a specified index of an existing array. There are various "get" actions based on the type of array value you are trying to get.
GUI:
Galaxy:
Length of Array
Returns an integer of the number of elements (the size) of an existing array.
Example
GUI:
Galaxy:
Both sets of code will debug "6" as this array consists of [2, 4, 7, 8, 10, 12].
For Each Index in Array
Loops through an array in order, setting a specified integer variable to the current key each round.
Example
GUI:
Galaxy:
Both sets of code produces this result in the debug area:
Set Array Value to Array Value
Sets the value of a specified index of an array to another specified value regardless of type.
(That's all the documentation for now, more will be coming up soon)
Download / Installation
You can download the library on Link Removed: http://www.mediafire.com/download/gv1duybbiq8jv6v/ImprovedArrays.SC2Mod .
To use the library in your map, follow these steps:
Changelog
Overview
Any questions / suggestions / feedback / bug report? Also note that this library is still under development and I will update it with new features (based on YOUR suggestions) soon.
Thanks!
This is awesome. I was just grumbling to myself about how annoying the editor's arrays are.
Why are there only 9 types supported? I need triggers, dialogs & dialog items.
Triggers are Strings (I believe), dialogs and dialog items are integers.
You can write your own conversion functions in GUI via just adding a return action into the function and writing lp_parameterName (= paremter's ID) into its custom code. That references the parameter and the code works, if the file types match. So, e.g. your function's paremter is named "val", then you write lp_val into the return action's custom script section.
I wasn't able to write my own conversion function (there already is a function to convert a trigger to a string, called "Trigger Function Name", but when I try to write a function that reverses that process like you described, I get an "implicit cast not allowed" compile error), but I was able to copy 'n' paste existing functions and change them to use triggers. I did the same for dialogs & dialog items.
Download: Link Removed: https://www.mediafire.com/?vwodfg1910ubhfx
Added functions:
SetDialog()
SetDialogItem()
SetTrigger()
PushDialog()
PushDialogItem()
PushTrigger()
GetDialog()
GetDialogItem()
GetTrigger()
SearchDialog()
SearchDialogItem()
SearchTrigger()
Also, I removed the unnecessary Void & Swarm dependencies and cut down the time it takes to open the mod in the editor from 3 seconds to 1 second.
Shouldn't someone (Chris97Ong) also publish this mod to Battle.net, so we can get automatic updates?
@temhawk: Go
I would export the library and import it into your map.
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)