Payscript allows the normal scope for variable access; a variable can be accessed within the scope where the variable was declared.
Example 1:
{
var x = 1;
var y = x * 2; // the variable x is accessible within this scope
}
Chain Scoping
Additionally, a variable can be accessed within the parent scope, but only until the execution of the next scope in the same level as the variable. This variation of the nature of variable scoping is unique to Payscripts, this is called Chain Scoping.
Example 1:
{
numeric input var DailyRate = 500;
numeric input var DaysWorked = 6;
}
{
// NOTE: DailyRate and DaysWorked are accessible here
numeric output var RegularPay = DailyRate * DaysWorked;
numeric input var SSS = 10;
numeric input var PHIC = 20;
numeric input var HDMF = 30;
}
// NOTE: DailyRate and DaysWorked are no longer accessible here and onwards
// NOTE: RegularPay, SSS, PHIC and HDMF are accessible here
numeric output var NetRegularPay = RegularPay – SSS – PHIC - HDMF;