Thanks for all your help. I have some sample code:
Dynamic[entE1]
Dynamic[entS1]
entE1 = 3000;
entS1 = 0;
SetAttributes[setEnergy, HoldAll]
setEnergy[x_, entE_, entShields_] :=
Module[{newE = entE, newS = entShields, tot},
tot = entE + entShields;
newE = (1 - x)*tot;
newS = x * tot;
(*
executing these lines updated variables passed.
numbers are passed, we get an error
*)
entE = newE;
entShields = newS;
Style[StringForm[
"percentage is is : `` \r Ent Energy is ``\r shields: ``",
NumberForm[x, 4], NumberForm[newE, 4], NumberForm[newS, 4]], 12,
Blue, FontFamily -> "Courier New"]]
val2FromSlider[myX_] := Module[{limits}, limits = 1;
Slider[myX, {0, limits}]]
showValue[x_] :=
Style[StringForm["value is : `` ",
NumberForm[x, 4, NumberSigns -> {"-", "+"}]], 12, Blue,
FontFamily -> "Courier New"]
{val2FromSlider[Dynamic[eEn]], showValue[Dynamic[eEn]],
Dynamic[setEnergy[eEn, entE1, entS1]], Dynamic[entE1],
Dynamic[entS1]}
This is a toy example of what I want to do. There are separate functions. One does the UI part, using a slider to set a percentage. There is a function that uses the current values of entE1 and entS1 to cumpute new values of the variables using the percentage eEn. The display code in setEnergy[] is there for debugging purposes.
This code works as written.
I tried to have setEnergy[] return the new values of entE1 and entS1, but if I did so, they were not dynamically updated. I tried wrapping Dynamic around the returned variables, to no avail. (I thought that this approach would work.)
I tried some other variations without much success.
As I said, this version works, and I can apply it to my real code. I would like to know if there is a more elegant solution.
Thanks.