Set Variable = Actor's name

Hi,
I'm trying to set var(x) = actor(y) name.
I tried setting var(x) = $gameActors.actor(y).name but it doesn't work.
I tested it with \v[x] in a text box and, instead of the name, it displayed:
"function () {
return this.name;
}"
What's wrong?
name()

Otherwise it's correct.
$gameActors.actor(id).name is a function that returns the private property this._name, so you can just set the variable to:
JavaScript:
$gameActors.actor(id)._name
or the function itself:
JavaScript:
$gameActors.actor(id).name()

The second solution is superfluous work for the computer, but a very meaningsless difference. But if you're someone who likes to optimize I'd use the first one, ._name.
do vars work if they are within ()? var (x)
if not then it should be var x,just a tip
To be fair I think Mark91 meant they set the variable in control variables. Using javascript, you're absolutely right you do var x, not var (x). For MV you shouldn't declare variables outside an object that's saved however because variables in the global scope isn't saved with the game.

In any case in modern javascript using var to declare variables is unecessary :LZSproud:
$gameActors.actor(id).name is a function that returns the private property this._name, so you can just set the variable to:
JavaScript:
$gameActors.actor(id)._name
or the function itself:
JavaScript:
$gameActors.actor(id).name()

The second solution is superfluous work for the computer, but a very meaningsless difference. But if you're someone who likes to optimize I'd use the first one, ._name.

The first one is what I needed^^
And thank you also for stating that the second variant requires superfluous work, optimizing is always better!
Always in debt
Stop it you're not in debt! Make something you're proud of and that'll be enough
$gameActors.actor(id).name is a function that returns the private property this._name, so you can just set the variable to:
JavaScript:
$gameActors.actor(id)._name
or the function itself:
JavaScript:
$gameActors.actor(id).name()

The second solution is superfluous work for the computer, but a very meaningsless difference. But if you're someone who likes to optimize I'd use the first one, ._name.
The amount of additional overhead between a function call and direct access is utterly trivial, and generally it's better to access properties via functions than directly when possible. This way, if you (or some plugin you add later) somehow modifies how names are stored (such as storing an object with first, last, etc name in the _name property) you can still get the desired result via the function call.

Edit: So in short, I'd suggest $gameActors.actor(id).name() over $gameActors.actor(id)._name
Well... You're right!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/set-variable-actors-name.120355/