Variables in AngelScript
In AngelScript, variables are explicitly declared and used by the compiler to check type-correctness of function calls.
void main()
{
// 'string' declares a variable of type string
string a = "initial";
print(a);
// You can declare multiple variables at once
int b = 1, c = 2;
print(b + " " + c);
// AngelScript will infer the type of initialized variables
auto d = true;
print(d);
// Variables declared without a corresponding
// initialization are zero-valued. For example, the
// zero value for an int is 0.
int e;
print(e);
// AngelScript doesn't have a shorthand syntax for
// declaring and initializing variables like ':=' in some languages.
// We simply use the standard assignment operator '='
string f = "apple";
print(f);
}To run this AngelScript code, you would typically embed it in a host application that provides the AngelScript runtime. The exact method of execution depends on your specific setup.
Here’s what the output would look like:
initial
1 2
true
0
appleIn AngelScript:
- Variables are declared with their type, like
string aorint b. - The
autokeyword can be used for type inference. - Multiple variables can be declared and initialized in one line.
- Variables are automatically initialized to their default values if not explicitly initialized.
- AngelScript doesn’t have a special shorthand syntax for variable declaration and initialization like some languages do.
Remember that AngelScript is typically used as a scripting language within a larger application, so the exact method of running and building programs may vary depending on your specific environment and setup.
Comments powered by Disqus