Object refering to itself by expression instead of name?

D4r4dragon
18 Feb 2021, 18:57This new question is very similar to the first, so I figured I should maybe try to reuse this post rather than make yet another. New error can be found in a post below.
FIXED- Referring to an object by expression instead of name?
I'm trying to modify objects without using their name directly. But keep getting the "Can't convert 'string' to expression result of 'Element'" with Enemy.name.
Enemies = Listcount (GetDirectChildren (Arena)) msg {"There are " + Enemies + " to fight.") Foreach {Enemy, (GetDirectChildren(Arena))) { msg ("It is " + Enemy.name + " turn.") //Action is an object script, I'm trying to use, in this case it is a clone/s of an object. do (Enemy.name, "Action") }
Pertex
18 Feb 2021, 19:03Try
Do(Enemy, "Action")

D4r4dragon
18 Feb 2021, 19:24Now it's saying "Object reference not set to an instance of an object."
jmnevil54
18 Feb 2021, 20:24Where is enemy defined? That may be where the glitch happens.

D4r4dragon
18 Feb 2021, 20:42Enemy is the variable for the For Each loop so I can cycle through all the enemies that were added.

Dcoder
18 Feb 2021, 20:47Does every direct child of Arena
actually have an Action
script attribute?
If so, maybe the second problem is a bad reference within your Action
script?

D4r4dragon
18 Feb 2021, 21:25No, the enemies have the script. And that's where I had the problem. The script is called "CombatPreference" not "Action..." I figured it out when I told a friend my issue and walked through my code. So yeah, the easy error that makes you feel stupid afterwards.

Dcoder
18 Feb 2021, 21:29No worries, all coders make silly mistakes!

D4r4dragon
19 Feb 2021, 19:05NEW QUESTION- I know that the player can be refer to itself with game.pov
But I don't know how to refer to a non player object within the object itself without needing to use it's name. I'm cloning objects so I need to know how to make the object figure out what it is by expression.

Dcoder
19 Feb 2021, 21:37Use the special variable this
, which refers to the object that the script belongs to (the script that you're editing). It can also refer to a command if the script is in the command's script, or an exit if in an exit's script, etc.