protected override MethodResult Get()
        {
            VarRef targetVariable = (VarRef)Parameters[0];

            if (targetVariable.Var is IndexedVar == false)
            {
                throw SyntaxErrorException.InvalidVarRefType(targetVariable.Var.Name, VarType.Indexed, ParameterLocations[0]);
            }

            IndexedVar var = (IndexedVar)targetVariable.Var;

            VariableChaseData chaseData = GetChaseData(var, TranslateContext);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                chaseData.Rate.SetVariable(new V_Number(0), targetVariable.Target)
                                );

            return(new MethodResult(actions, null));
        }
        public VariableChaseData GetChaseData(IndexedVar var, TranslateRule context)
        {
            var existingChaseData = context.ParserData.Chasing.FirstOrDefault(cd => cd.Var == var);

            if (existingChaseData != null)
            {
                return(existingChaseData);
            }

            IndexedVar destination = context.VarCollection.AssignVar(null, $"'{var.Name}' chase destination", var.IsGlobal, null);
            IndexedVar rate        = context.VarCollection.AssignVar(null, $"'{var.Name}' chase duration", var.IsGlobal, null);

            VariableChaseData newChaseData = new VariableChaseData(var, destination, rate);

            context.ParserData.Chasing.Add(newChaseData);

            Rule chaseRule = new Rule(
                Constants.INTERNAL_ELEMENT + "Chase Variable: " + var.Name,
                var.IsGlobal ? RuleEvent.OngoingGlobal : RuleEvent.OngoingPlayer
                );

            chaseRule.Conditions = new Condition[]
            {
                new Condition(
                    rate.GetVariable(),
                    Operators.NotEqual,
                    new V_Number(0)
                    )
            };
            chaseRule.Actions = ArrayBuilder <Element> .Build(
                UpdateVariable(var, destination, rate),
                A_Wait.MinimumWait,
                new A_LoopIfConditionIsTrue()
                );

            context.ParserData.AdditionalRules.Add(chaseRule);

            return(newChaseData);
        }