Core Function Assign

From Sputnik Wiki
Jump to: navigation, search
Assign( <varname>, <data>, <flag> )

Contents

Description

Assigns a variable by name with the data.

Parameters

varname

The name of the variable you wish to assign.

data

The data you wish to assign to the variable.

flag

Optional; Controls the way that variables are assigned (add required options together):

0 = (default) Create variable if required
1 = Force creation in local scope
2 = Force creation in global scope
4 = Force creation in max depth local scope (Such as a classes My)
8 = Fail if variable does not already exist

Return Value

Success: Returns 1.

Failure: Returns 0 if unable to create/assign the variable.

Remarks

None

Example

// Create SCOPE ANY  (Likes to prioritize local)
if(  Assign("Test", 1221)   )
{
	println("Test: $test");
}
 
// Create SCOPE LOCAL
if(  Assign("Test2", 1221, 1)   )
{
	println("Test2: $test2");
}
 
// Create SCOPE GLOBAL
if(  Assign("Test3", 1221, 2)   )
{
	println("Test3: $test3");
}
 
// Set variable in SCOPE GLOBAL
if(  Assign("Test3", 777, 2)   )
{
	println("Test3 set to: $test3");
}
 
// Set variable in SCOPE GLOBAL IF IT EXISTS ONLY
if(  Assign("Test4", 1333, 2 | 8)   )
{
	println("Test4 set to: $Test4");
}
else
{
	println("Variable Test4 does not exist");
}
 
if(  !Assign("Testy", 1221, 8)   )
{
	println("Variable \$Testy does not exist");
}


Class lol
{
	Function __Construct()
	{
		Assign("Test", 1221, 4); // Force creation at base class level
	}
	Function hehe()
	{
		println("Test in class: $test");
	}
};
$a = new lol();
$a->hehe();
println("Test var here is:: " . $test);
println("Test out class: " . $a->$test);


Class lol
{
	Function __Construct()
	{
		// Fail is variable dont exist
		if(!Assign("Test", 1221, 4 | 8))
		{
			println("Variable does not exist");
		}
	}
	Function hehe()
	{
		println("Test in class: $test");
	}
};
$a = new lol();
$a->hehe();
println("Test var here is:: " . $test);
println("Test out class: " . $a->$test);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox