(09-15-2014, 12:25 AM)FlawlessHappiness Wrote: What is a double?
I've never heard of it ^_^
Also, the primitive way works, yes, but when scripting in HPL it'll only work inside the brackets you're in.
If you suddenly want to use the same variable as you used in a previous function, then you can't because you used the primitive way, which is now erased from the memory of the script.
It depends where you declare it. If you add it outside all your blocks, it can be accessed anywhere.
int value = 1;
void OnStart()
{
int value2 = 2;
AddDebugMessage("value == " + value, false); //prints 1
AddDebugMessage("value == " + value2, false); //prints 2
}
void Callback(string &in asParam)
{
AddDebugMessage("value == " + value, false); //also prints 1
AddDebugMessage("value == " + value2, false); //crashes because value2 is not found
}
If the primitive is declared inside a block, the scope only allows it to be used within that block. Once it's finished, it's erased from memory.
I believe the values are static within the file, so changing the value in one block will affect the overall value of the primitive throughout the file. The original value is only initial.
int value = 1;
void OnStart()
{
value = 2;
AddDebugMessage("value == " + value, false); //prints 2
}
void Callback(string &in asParam)
{
AddDebugMessage("value == " + value, false); //still prints 2
value = 4;
AddDebugMessage("value == " + value, false); //prints 4
}
Primitives can also be declared as null (no value). If you know you set the variable to a value before you use it, it can help make the code more stable.
int value; //declared without a value
void Callback(string &in asParam)
{
if(value == null) return; //checks if variable has no value, and if so, cancels this block.
value = 4;
AddDebugMessage("value == " + value, false); //prints 4
}
Null isn't very important to use in your script as a beginner or even intermediate. I don't think I've used it much myself except no value declarations. Any variable can be assigned null if nothing else is specified. Null is often a crash cause if you expect to get a value. Important to note that null is not the same as 0.
Null isn't directly present in HPL's script variables though. You can probably lure it in there by doing something like
SetLocalVarInt("number", value);
where value is currently null. But I think I'll stop digging deeper here
Most of this is unnecessary in most cases of HPL scripting.