This is an old revision of the document!
Script Environments
With the exception of the shared table all Lua scripts run in the environment they're first called upon and by default have no access to variables or methods in other environments. These environments are the OBJ, CH/MOB, ROOM, AREA spaces, along with a few others. There are several ways to "break out" of an environment and affect external environments.
Simple Interactions
The most common way to manipulate an outside environment is with the Prog Trigger mechanism. Mob Progs, Obj Progs, Room Progs and Area Progs all return a CH object, and some return an OBJ object.
For example, in this simple script, a Mob Prog will return the name of a CH, which is a property of CH.
-- GRALL. Let's say HI! to PCs if ch.ispc then – ispc is also a property of CH say("HI "..ch.name.."!") end
These simple interactions often depend on the method that wants to be called being available to the environment that is calling it. For example, damage() is a method of CH, so if a mob wanted to damage a PC upon entering a room, it would be quite simple:
-- GRALL. Our PC entered this room mob:damage(ch, 5000, true, "holy")
And now our char has been damaged for 5000 hitpoints.
Because damage() is a method of CH, this could easily be rewritten so that the PC damages themselves:
-- GRALL. Our PC entered this room ch:damage(ch, 5000, true, "holy")
There is no qualitative difference between the two versions.