2

I want a shifter list for a input buffer. My code is:

//Simulate input whit Slider. Is work perfect. Only work for changes by the user.

list = Table[0, {10}]; Slider[Dynamic[b, (b = #; list = Take[Join[list, {b}], -10]) &], {0, 10, 1}] Dynamic@list

//x is a simulation of data input

Dynamic[x = RandomInteger[10], UpdateInterval -> 1]

//Shifter list. As 'a' change, the code is replayed.

Dynamic[Take[AppendTo[a, x], -10],UpdateInterval -> 1]

I want to run the code only for 'x' changes. No for changes of 'a'. Help me, please.

1 Answers1

0

Not sure how your Slider is related to the question but here's an answer:

use TrackedSymbols to specify what can trigger second Dynamic.

Dynamic[x = RandomInteger[10], UpdateInterval -> .2]
a = {};
Dynamic[a = PadLeft[Flatten@{a, x}, 10], TrackedSymbols :> {x}]

no need for UpdateInterval then.

Keep in mind that operations in Dynamic will be performed only when such cell is visible. Maybe better approach is to use ScheduledTasks or regular Do + Pause.

Kuba
  • 791
  • 8
  • 14