// returns whether the name exists as a variable, in the scope of the current instance. // The interpreter checks array bounds with Variable.CheckIndex(). public static bool VariableExists(string name) { if (DeclaredVariables.Contains(name)) { return(ScopedVariables.ContainsKey(name)); } return(globalvars.Contains(name) || Current.VariableExists(name)); }
// returns whether the name exists as a variable, in the scope of the given instance. // example: x = VariableExists(Env.self, "t"); public static bool VariableExists(int id, string name) { switch ((InstanceTarget)id) { case InstanceTarget.Self: return(Current != null && Current.VariableExists(name)); case InstanceTarget.Other: return(Other != null && Other.VariableExists(name)); case InstanceTarget.All: return(Instances.Any(e => e.VariableExists(name))); case InstanceTarget.Noone: return(false); case InstanceTarget.Global: return(GlobalVariableExists(name)); default: return(Instances.Any(inst => inst.id == id && !inst.Destroyed && inst.VariableExists(name))); } }