Game Engine Architecture

(Ben Green) #1
809

if (argCount != 1)
{

DcErrorMessage("get-object-pos:
Invalid arg count.\n");
return result;
}
if (aArgs[0].GetType() != Variant::TYPE_STRING_ID)
{

DcErrorMessage("get-object-pos: Expected
string id.\n");
return result;
}

StringId objectName = aArgs[0].AsStringId();
GameObject* pObject = GameObject::LookUpByName
(objectName);

if (pObject == NULL)
{

DcErrorMessage(
"get-object-pos: Object ‘%s’ not found.\n",
objectName.ToString());
return result;
}
result. SetAsVector(pObject->GetPosition());
return result;
}

14.8.5.2. Game Object Handles


Script functions oft en need to interact with game objects, which themselves
may be implemented partially or entirely in the engine’s native language. The
native language’s mechanisms for referencing objects (e.g., pointers or refer-
ences in C++) won’t necessarily be valid in the scripting language. (It may not
support pointers at all, for example.) Therefore, we need to come up with
some reliable way for script code to reference game objects.
There are a number of ways to accomplish this. One approach is to refer to
objects in script via opaque numeric handles. The script code can obtain object
handles in various ways. It might be passed a handle by the engine, or it might
perform some kind of query, such as asking for the handles of all game objects
within a radius of the player or looking up the handle that corresponds to a
particular object name. The script can then perform operations on the game


14.8. Scripting

Free download pdf