Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variables
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#4
RE: Variables

(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.

PHP Code: (Select All)
int value 1;
void OnStart()
{
    
int value2 2;
    
AddDebugMessage("value == " valuefalse); //prints 1
    
AddDebugMessage("value == " value2false); //prints 2
}

void Callback(string &in asParam)
{
    
AddDebugMessage("value == " valuefalse); //also prints 1
    
AddDebugMessage("value == " value2false); //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.

PHP Code: (Select All)
int value 1;
void OnStart()
{
    
value 2;
    
AddDebugMessage("value == " valuefalse); //prints 2
}

void Callback(string &in asParam)
{
    
AddDebugMessage("value == " valuefalse); //still prints 2
    
value 4;
    
AddDebugMessage("value == " valuefalse); //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.

PHP Code: (Select All)
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 == " valuefalse); //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
PHP Code: (Select All)
SetLocalVarInt("number"value); 
where value is currently null. But I think I'll stop digging deeper here Tongue
Most of this is unnecessary in most cases of HPL scripting.

(This post was last modified: 09-15-2014, 07:38 AM by Mudbill.)
09-15-2014, 07:32 AM
Find


Messages In This Thread
Variables - by FlawlessHappiness - 09-14-2014, 10:25 PM
RE: Variables - by Mudbill - 09-15-2014, 12:17 AM
RE: Variables - by FlawlessHappiness - 09-15-2014, 12:25 AM
RE: Variables - by Mudbill - 09-15-2014, 07:32 AM
RE: Variables - by Romulator - 09-15-2014, 08:16 AM
RE: Variables - by FlawlessHappiness - 09-15-2014, 11:46 AM
RE: Variables - by Romulator - 09-15-2014, 12:21 PM
RE: Variables - by FlawlessHappiness - 09-15-2014, 12:47 PM



Users browsing this thread: 1 Guest(s)