private void GetInitialValue() { // Get the initial value. if (_initalValueContext != null) { ParseInfo parseInfo = this.parseInfo; // Store the initial value's restricted calls. RestrictedCallList restrictedCalls = null; if (_handleRestrictedCalls) { restrictedCalls = new RestrictedCallList(); parseInfo = parseInfo.SetRestrictedCallHandler(restrictedCalls); } // Parse the initial value. InitialValue = parseInfo.SetExpectingLambda(CodeType).GetExpression(_operationalScope, _initalValueContext); // If the initial value's type is constant, make sure the constant type's implements the variable's type. if (InitialValue?.Type() != null && InitialValue.Type().IsConstant() && !InitialValue.Type().Implements(CodeType)) { parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", _initalValueContext.Range); } // If the variable's type is constant, make sure the value's type matches. else if (CodeType != null && CodeType.IsConstant() && (InitialValue.Type() == null || !InitialValue.Type().Implements(CodeType))) { parseInfo.Script.Diagnostics.Error($"Expected a value of type '" + CodeType.GetName() + "'", _initalValueContext.Range); } // Check restricted calls. if (_handleRestrictedCalls) { foreach (RestrictedCall call in restrictedCalls) { // If the variable type is global, or the variable type is player and the restricted call type is not player... if (VariableType == VariableType.Global || (VariableType == VariableType.Player && call.CallType != RestrictedCallType.EventPlayer)) { // ... then add the error. parseInfo.Script.Diagnostics.Error(call.Message, call.CallRange.range); } } } } }