I have the following code that shows how the coordinates of the point p1 changes when the user moves it around.
I am trying to see how to point is represented as a complex number z1. But I can’t figure out why it doesn’t work - the value of z1 stays at 1+2i. I want z1 value to be updated according to the value of p1.
Let’s start with some info about Dynamic. Dynamic is just a wrapper. It tells the front end to refresh the display of some expression whenever the variables that that expression depend on change. So, Dynamic[z1] will only ever get its display refreshed if z1 gets changed (z1 is the only variable in the expression). But in your example, z1 never gets changed. That leads to…
Using Set (e.g. z1=Complex@@p1) is defining the OwnValues for a symbol. It’s not defining some procedure to be executed in the future. Once the Set is executed, it’s finished and is never consulted again (well, unless you re-execute that expression). So, after z1 is defined with Set, any later usage of z1 is replaced based on z1’s OwnValues.
The simplest way to get what I assume you want would probably be to replace Dynamic[z1] with Dynamic[z1 = Complex @@ p1]. There are other ways that might be better for your context, but that’s what came to my mind first. That’s assuming that you actually need the variable z1. If not, then you could simplify it even more to just Dynamic[Complex @@ p1]