Error Messages/41107
Error message variants
Encountered Subscript(*, Time, *) referencing 'future' Time. Encountered Slice(*, Time, *) referencing 'future' Time. Consider using a conditional in the third parameter to ensure the third parameter is not greater than Time.
Cause
In a Dynamic function, you may express the value at Time = t in terms of earlier values. If, however, you attempt to define the value at Time = t based on future value, the error results. A trivial case would be:
Dynamic(1, Self[Time = Time + 1])
When the error indicates that Subscript is to blame, this may be due to an explicit call to the Subscript function, or it may be resulting from a subscript expression of the form expr[Time = x]. Similarly, if it reads Slice, it may either be an explicit call to the Slice function, or a slice operator of the form expr[@Time = n].
The error may occur in less obvious situations when position parameter is computed, or is an array. For example, suppose you have an index named T defined to be have the same index values as Time. If you attempted a re-indexing operation such as:
Dynamic(1, A[Time = T])
you would encounter this error, since when Dynamic is evaluating at Time = 2
, T contains the value 3, etc. Because a "hard error" occurs in this case, rather than just a warning, you can't simply ignore warnings as is possible in other subscript-out-of-range instances. Hence, you may need to include a conditional (or other expression) in the third parameter, as well as a conditional outside, as follows:
Dynamic(1, If T >= Time Then Null Else A[Time = (If T >= Time Then 1 Else T)])
The conditional inside the third parameter serves only to ensure that it never references a Time value beyond the computed range. The following variation is often more syntactically convenient:
Dynamic(1, If T >= Time Then Null Else A[Time = Min([T, Time - 1])])
Remedies
Reformulate the input to your function (as advised above) so that the function parameters do no reference a future time value.
Enable comment auto-refresher