Object refering to itself by expression instead of name?

This 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")
}

Try
Do(Enemy, "Action")


Now it's saying "Object reference not set to an instance of an object."


Where is enemy defined? That may be where the glitch happens.


Enemy is the variable for the For Each loop so I can cycle through all the enemies that were added.


Does 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?


No, 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.


No worries, all coders make silly mistakes!


NEW 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.


Use 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.


Log in to post a reply.

Support

Forums