1
$\begingroup$

I have this very simple program:

n=0;
{
Button["Play", a = RandomInteger[10];b = RandomInteger[10];n+=1 ],
Dynamic[a], "vs", Dynamic[b], "draw number:", Dynamic[n]
}

When I run it, only the first variable visually updates in the output line. If I ask for the value of b or n, I can see that they do change every time, but it is not dynamically visible. This is a big problem for me. Is it ab browser issue? Sometimes the b gets updated, sometimes not...

what it looks like when I run it

$\endgroup$
10
  • $\begingroup$ I see both a and b update, so I don't know what trouble you're having with b. But n was never given a value, so n+=1 can't actually have an effect. You need to initialize n to some value . $\endgroup$
    – lericr
    Commented Apr 26, 2023 at 18:27
  • $\begingroup$ sorry yes. in my notebook I sent n=0 before I run this. Could it be like a browser issue? is there a recommended browser to run Wolfram-cloud? $\endgroup$ Commented Apr 26, 2023 at 18:34
  • $\begingroup$ I tried switching a and b in the dynamic at the Bottom, and still only a gets updated when I click the button. $\endgroup$ Commented Apr 26, 2023 at 18:44
  • 1
    $\begingroup$ Indeed. I just tried in in wolframcloud (using Safari), and I see the behavior you're describing. $\endgroup$
    – lericr
    Commented Apr 26, 2023 at 19:00
  • 1
    $\begingroup$ Hello user3447795, I think it would make sense to mention in the question or even the title that you encounter this problem in the cloud only. That will avoid a lot of people trying this and not seeing the problem. I think the majority of readers here will typically still use the desktop version... $\endgroup$ Commented Apr 28, 2023 at 20:36

1 Answer 1

1
$\begingroup$

It looks like it might be a "limitation" of the cloud version... although it sometime actually work for a short moment. I did, however, find a work around:

n=0;
{
Button["Play", a = RandomInteger[10];b = RandomInteger[10];n+=1 ],
Dynamic[a], "vs", Dynamic[b+a-a], "draw number:", Dynamic[n+a-a]
}

The first variable that gets dynamically computer refresh, so if we use it in the other Dynamic[] functions, they refresh "as expected"...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.