I have this function to set the movement of cubes on the canvas (random), everyVar
is the variables that will be used and a,b,c,d
are functions for +,-,*,/
(sorry if its confusing). Is there a way to find the name of the variable instead of the value it holds; I have "user.s = a(b(c(d(r, 2), e), w), q);
" and i need a way to put that in a repeating function so that the variables stay the same but the information updates, but if i put it somewhere else as it is it will have different variables. I cant just set another variable like myVariable = q
because it will save the number not the variable itself (i need it to say user.y instead of 300 for example). Please make your answer as simple as possible as I am a beginner as you can probably tell.
function setMovement(user){
var everyVar = [user.x, user.y, user.direction, user.distance]
var q = everyVar[Math.floor(Math.random()*everyVar.length)];
var w = everyVar[Math.floor(Math.random()*everyVar.length)];
var e = everyVar[Math.floor(Math.random()*everyVar.length)];
var r = everyVar[Math.floor(Math.random()*everyVar.length)];
user.s = a(b(c(d(r, 2), e), w), q);
a = operators[Math.floor(Math.random()*operators.length)]
b = operators[Math.floor(Math.random()*operators.length)]
c = operators[Math.floor(Math.random()*operators.length)]
d = operators[Math.floor(Math.random()*operators.length)]
}