public void end(string action, string[] words, RihaNode[] previuseActionResult) { string setPattern = @"\s*end\s+scope\s*"; if (MatchesRegex(action, setPattern)) { if (scopes.Count > 0) { RihaScope acctiveScope = scopes.Last(); if (acctiveScope.type == ScopeType.loop && acctiveScope.iteration < acctiveScope.parameter.GetSize() - 1) { acctiveScope.iteration++; acctiveScope.endLine = lineNumber; lineNumber = acctiveScope.startLine; } else { scopes.Remove(acctiveScope); } } } }
public void Execute(string command) { codeOutput = ""; command.Replace("<br>", "\n"); try{ variableMemory = new Dictionary <string, RihaNode>(); scopes = new List <RihaScope>(); string[] commands = command.Split(new [] { '\r', '\n' }); string commandLine = ""; Resource requiredEnergy = new Resource() { resourceID = 2, amount = commands.Length * 5 }; if (!PlayerData.HasEnoughResource(requiredEnergy)) { codeOutput = "NOT ENOUGH ENERGY!\nREQUIRED: " + requiredEnergy.amount; return; } PlayerData.RemoveResource(requiredEnergy); for (lineNumber = 0; lineNumber < commands.Length; lineNumber++) { string line = commands[lineNumber]; if (scopes.Count > 0) { RihaScope acctiveScope = scopes.Last(); if (!MatchesRegex(line, @"\s*end\s+scope\s*")) { // Check if (acctiveScope.type == ScopeType.check) { if (!(bool)acctiveScope.parameter.GetValue()) { continue; } } // Loop else if (acctiveScope.type == ScopeType.loop) { if (acctiveScope.parameter.GetSize() < 1) { continue; } } } } if (MatchesRegex(line, @"\s*\/\/.*")) { continue; } commandLine += line; if (!IsEOL(line)) { continue; } List <string> actions = SplitActions(commandLine); ExecuteAction(actions); commandLine = ""; } } catch (Exception e) { codeOutput += "\n<color=red><b>ERROR OCCURRED:</b></color>" + e.Message; Debug.LogError(e); } }