If you have an entity in your world called "door_blue" say, then you can access the entity directly by using something like the following: door_blue:open(). As there is no variable called door_blue in the local scope it goes off and looks for an entity in the dungeon with the same name - which works and everyone is happy.
The problem with the example you have posted is that you are storing the ID of an entity in a local variable. So, when you print the variable it shows the correct entity name, but when you do this...
name_of_the_light:deactivate();
What you are actually trying to do is call the method 'deactivate' on the string object called name_of_the_light. Luckily, there is a handy method to get a reference to the entity itself from the name, so you can do the following...
Code: Select all
local light_entity = findEntity(name_of_the_light);
light_entity:deactivate();
And this allows you to call deactivate on the object itself. A good idea is to make sure that the entity is actually found - because if no entity is found the above example will crash! This version is safer...
Code: Select all
local light_entity = findEntity(name_of_the_light);
if ( light_entity ~= nil ) then
light_entity:deactivate();
end
Hope this helps!