WatchManager

Allows entities to function off-screen.

About

This is a global object that can always be accessed.

Sometimes you want Entities to continue to function even when off screen or on a different Map.

For instance, if an NPC needs to walk to his bed and sleep, he needs to be added to the watch manager so he can function offscreen.

When toggling the FPS display (Ctrl-F) the number after the W indicates how many entities are currently being “watched”.

Usage

//insure this entity will function for the next 5 seconds no matter where it is
GetWatchManager:Add(this, 1000*5); (5000 milliseconds)
Summary
WatchManagerAllows entities to function off-screen.
Member Functions
Add
Remove
GetWatchCount
Related Constants
C_TIME_CONSTANTSUsed with WatchManager::Add.
C_TIME_FOREVERA very large number, as close to “forever” as we can get with milliseconds of time.

Member Functions

Add

nil Add(Entity ent, number timeToWatchMS)

If a function called “OnWatchTimeout” exists in the Entity’s namespace, it will be called when the watch times-out (finishes).  The function must accept a parameter that will be a boolean set to TRUE if the Entity is currently on the screen.  If an Entity is deleted who was on the watch list, it is automatically removed.

Usage

//we want to know when the watch is over
OnWatchTimeout(bIsOnScreen)
LogMsg("Watch complete, no longer letting this entity run on its own!");

if (bIsOnScreen) then
LogMsg("Entity is currently on the screen!");
else
LogMsg("Entity is off screen.");
end
end

Notes

If you would like an entity to become as its map is loaded, you can call this function in an entity’s OnMapInsert() script function.

Parameters

entThe Entity that should remain active regardless of where it is.
timeToWatchMSHow long before this Entity returns to a normal state.  (ie, unwatched) Use C_TIME_FOREVER to stay watched forever.

Remove

nil Remove(Entity ent)

Removes this Entity from the watch list.

Parameters

The Entity that shouldn’t be watched (run off-screen) anymore.

GetWatchCount

number GetWatchCount()

Returns:

How many entities are currently being watched.  (Allowed to function off-screen)

Related Constants

Summary
C_TIME_CONSTANTSUsed with WatchManager::Add.
C_TIME_FOREVERA very large number, as close to “forever” as we can get with milliseconds of time.

C_TIME_CONSTANTS

C_TIME_FOREVER

A very large number, as close to “forever” as we can get with milliseconds of time.

The Entity object.
A map is a single area that can be any size and contain any amount of tiles, including Entities and TilePic’s.
A very large number, as close to “forever” as we can get with milliseconds of time.