TeaseAI_CE.Scripting.Controller.next C# (CSharp) Method

next() private method

Executes the next line on the stack.
private next ( StringBuilder output ) : bool
output StringBuilder
return bool
		internal bool next(StringBuilder output)
		{
			if (AutoFill && stack.Count == 0 && queue.Count == 0 && emptyQuery.IsSet)
			{
				AddFromEmptyQuery(new Logger("Controller." + Id));
			}

			// populate stack with items in the queue.
			if (queue.Count > 0)
			{
				lock (queue)
				{
					foreach (Context item in queue)
						stack.Push(item);
					queue.Clear();
				}
			}

			if (stack.Count == 0)
				return false;

			// try to execute top item.
			var scope = stack.Peek();
			if (scope.Line >= scope.Block.Lines.Length)
			{
				stack.Pop();
				return next(output);
			}
			else
			{
				scope.Root.Log.SetId(scope.Block.Lines[scope.Line].LineNumber);
				// exec current line
				Line line = scope.Block.Lines[scope.Line];
				VM.ExecLine(scope, line.Data, output);

				if (scope.ExitLine)
					scope.Repeat = false;

				// always continue when validating.
				if (scope.Root.Valid == BlockBase.Validation.Running)
				{
					scope.Exit = false;
					scope.Return = false;
				}

				// advance to next line, if repeat is false.
				if (scope.Repeat == false)
					++scope.Line;
				else
					scope.Repeat = false;

				if (scope.Exit)
					stack.Clear();
				else if (scope.Return)
					stack.Pop();
				// push sub block if exists
				else if (line.Lines != null && scope.ExitLine == false)
				{
					stack.Push(new Context(this, scope.Root, line, 0, new Dictionary<string, Variable>(scope.Variables)));
					if (stack.Count > 128)
					{
						scope.Root.Log.ErrorF(StringsScripting.Formatted_Stack_too_big, 128);
						stack.Clear();
					}
				}
				// pop off stack, if no lines left.
				else if (scope.Line >= scope.Block.Lines.Length)
					stack.Pop();

				scope.ExitLine = false;
				return true;
			}
		}
		/// <summary>

Usage Example

Example #1
0
		private void validateScript(Controller c, Script s, Dictionary<string, Variable> vars, StringBuilder output)
		{
			// if script has never been validated, but has errors, then do not validate, they are parse errors.
			if (s.Valid == BlockBase.Validation.NeverRan && s.Log.ErrorCount > 0)
			{
				s.SetValid(false); // will set valid to failed.
				return;
			}

			s.SetValid(true);
			if (s.List)
			{
				vars.Clear();
				s.ExecuteAsList(new Context(c, s, s, 0, vars), output);
			}
			else
			{
				c.Add(s);
				while (c.next(output))
				{

				}
			}
			s.SetValid(false);
		}
All Usage Examples Of TeaseAI_CE.Scripting.Controller::next