Types
In HaasScript, like in many other programming languages, there are different variable types. Each type of variable can hold different values, and they are used for different purposes. Here are the main variable types in HaasScript:
Number
A number is a variable type that stores numerical values. This can be an integer (a whole number) or a floating-point number (a number with a decimal point). Examples of numbers in HaasScript are:
local integerNumber = 42
local floatingPointNumber = 3.14
String
A string is a variable type that stores text. Strings are surrounded by quotes (either single or double quotes) in HaasScript. Examples of strings are:
local name = "Alice"
local message = 'Hello, world!'
Boolean
A boolean is a variable type that can hold one of two values: true
or false
. Booleans are often used in conditional statements to control the flow of a program. Examples of booleans are:
local isItRaining = false
local isHaasScriptAwesome = true
Nil
The nil
type is a special value in HaasScript that represents nothing. It is often used to indicate that a variable has no value or has not been initialized yet. Examples of nil
are:
local myVariable = nil
Table
A table is a variable type that can hold multiple values. In other programming languages, this type is sometimes called an “array” or a “dictionary”. Tables in HaasScript can be indexed by either numbers or strings. Here is an example of a table:
local myTable = {
name = "Alice",
age = 30,
hobbies = {"reading", "hiking"}
}
In the example above, myTable
is a table that contains three values: a string (name
), a number (age
), and another table (hobbies
), which contains two strings.
Function
A function is a variable type that can hold a block of code. Functions are used to encapsulate a piece of functionality that can be reused throughout a program. Here is an example of a function:
local function addNumbers(a, b)
return a + b
end
In the example above, addNumbers
is a function that takes two arguments (a
and b
) and returns their sum.
Userdata
Userdata is a variable type that is used to store data that is handled by HaasScript directly. An example of this type is HNC()
which creates a custom type of array and is also the type of the returned values from price data commands, such as ClosePrices()
.
Conclusion
These are the main variable types in HaasScript. By understanding the different variable types and how they are used, you can write more efficient and effective code.