Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
orxonox::Script Class Reference

The Script class lets you execute a piece of code, either the normal way or in lua, through XML. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/modules/objects/Script.h>

Inheritance diagram for orxonox::Script:
orxonox::BaseObject orxonox::ClientConnectionListener orxonox::OrxonoxClass orxonox::Listable orxonox::Configurable orxonox::Destroyable orxonox::Identifiable orxonox::Listable orxonox::Identifiable

Public Member Functions

 Script (Context *context)
 Constructor. More...
 
virtual ~Script ()
 Destructor. More...
 
virtual void clientConnected (unsigned int clientId) override
 Callback that is called when a new client has connected. More...
 
virtual void clientDisconnected (unsigned int clientid) override
 
void execute (unsigned int clientId, bool onLoad=false)
 Executes the Scripts code for the input client, depending on the mode. More...
 
const std::string & getCode () const
 Get the code that is executed by this Script. More...
 
const std::string & getMode (void)
 Get the mode of the Script. More...
 
bool getNeedsGraphics (void)
 Get whether the code to be executed needs graphics to work. More...
 
int getTimes (void)
 Get the number of times this Script is executed at the most. More...
 
bool isForAll (void)
 Get whether the Script executes its code for all players or just for the player triggering the Script. More...
 
bool isOnLoad (void)
 Get whether this Script is executed onLoad. More...
 
void setCode (const std::string &code)
 Sets the code that is executed by this Script. More...
 
void setForAll (bool forAll)
 Set whether the code is executed for all players or just for the player triggering the Script. More...
 
void setMode (const std::string &mode)
 Sets the mode of the Script. More...
 
void setNeedsGraphics (bool needsGraphics)
 Set whether the code to be executed needs graphics to work. More...
 
void setOnLoad (bool onLoad)
 Set whether this Script is executed onLoad or not. More...
 
void setTimes (int times)
 Set the number of times this Script is executed at the most. More...
 
bool trigger (bool triggered, BaseObject *trigger)
 Is called when an event comes in trough the event port. More...
 
virtual void XMLEventPort (Element &xmlelement, XMLPort::Mode mode) override
 Creates a port that can be used to channel events and react to them. More...
 
virtual void XMLPort (Element &xmlelement, XMLPort::Mode mode) override
 Method for creating a Script object through XML. More...
 
- Public Member Functions inherited from orxonox::BaseObject
 BaseObject (Context *context)
 Constructor: Registers the object in the BaseObject-list. More...
 
virtual ~BaseObject ()
 Destructor. More...
 
void addEventListener (BaseObject *listener)
 Adds an object which listens to the events of this object. More...
 
void addEventSource (BaseObject *source, const std::string &state)
 Adds a new event source for a specific state. More...
 
void addTemplate (const std::string &name)
 Adds a Template to the object. More...
 
void addTemplate (Template *temp)
 Adds a Template to the object. More...
 
virtual void changedActivity ()
 This function gets called if the activity of the object changes. More...
 
virtual void changedMainStateName ()
 This function gets called if the main state name of the object changes. More...
 
virtual void changedName ()
 This function gets called if the name of the object changes. More...
 
virtual void changedVisibility ()
 This function gets called if the visibility of the object changes. More...
 
void fireEvent (const std::string &name="")
 Fires an event (without a state). More...
 
void fireEvent (bool activate, const std::string &name="")
 Fires an event which activates or deactivates a state. More...
 
void fireEvent (bool activate, BaseObject *originator, const std::string &name="")
 Fires an event which activates or deactivates a state with agiven originator (the object which triggered the event). More...
 
void fireEvent (Event &event)
 Fires an event, using the Event struct. More...
 
BaseObjectgetCreator () const
 
BaseObjectgetEventListener (unsigned int index) const
 Returns an event listener with a given index. More...
 
BaseObjectgetEventSource (unsigned int index, const std::string &state) const
 Returns an eventsource with a given index. More...
 
const XMLFilegetFile () const
 Returns a pointer to the XMLFile that loaded this object. More...
 
const std::string & getFilename () const
 Returns the levelfile that loaded this object. More...
 
GametypegetGametype () const
 
LevelgetLevel () const
 
const std::string & getLoaderIndentation () const
 Returns the indentation of the debug output in the Loader. More...
 
const std::string & getMainStateName () const
 Returns the name of the main state. More...
 
const std::string & getName () const
 Returns the name of the object. More...
 
NamespacegetNamespace () const
 
const std::string & getOldName () const
 Returns the old name of the object. More...
 
ScenegetScene () const
 
virtual uint32_t getSceneID () const
 
const std::set< Template * > & getTemplates () const
 Returns the set of all aplied templates. More...
 
const mboolisActive () const
 Returns the state of the objects activity. More...
 
bool isInitialized () const
 Returns if the object was initialized (passed the object registration). More...
 
const mboolisVisible () const
 Returns the state of the objects visibility. More...
 
virtual void processEvent (Event &event)
 Processing an event by calling the right main state. More...
 
void removeEventSource (BaseObject *source)
 Removes an eventsource (but doesn't unregister itself at the source). More...
 
void setActive (bool bActive)
 Sets the state of the objects activity. More...
 
void setCreator (BaseObject *creator)
 
void setFile (const XMLFile *file)
 Sets a pointer to the xml file that loaded this object. More...
 
void setGametype (const StrongOrWeakPtr< Gametype > &gametype)
 
void setLevel (const StrongOrWeakPtr< Level > &level)
 
void setLoaderIndentation (const std::string &indentation)
 Sets the indentation of the debug output in the Loader. More...
 
void setMainState (bool state)
 Sets the main state of the object to a given boolean value. More...
 
void setMainStateName (const std::string &name)
 Sets the name of the main state (used for event reactions). More...
 
void setName (const std::string &name)
 Sets the name of the object. More...
 
void setNamespace (const StrongOrWeakPtr< Namespace > &ns)
 
void setScene (const StrongOrWeakPtr< Scene > &scene, uint32_t sceneID)
 
void setVisible (bool bVisible)
 Sets the state of the objects visibility. More...
 
- Public Member Functions inherited from orxonox::OrxonoxClass
 OrxonoxClass ()
 
OrxonoxClassoperator= (const OrxonoxClass &)=default
 
- Public Member Functions inherited from orxonox::Configurable
 Configurable ()
 
void setConfigValues ()
 Function to collect the SetConfigValue-macro calls. More...
 
- Public Member Functions inherited from orxonox::Listable
 Listable ()
 Constructor: Allocates space in the element list. More...
 
 Listable (Context *context)
 Constructor: Allocates space in the element list and assigns the context. More...
 
virtual ~Listable ()
 Destructor: Removes the object from the object-lists. More...
 
ContextgetContext () const
 
void setContext (Context *context)
 Changes the context. More...
 
void unregisterObject ()
 Removes this object from the object-lists. More...
 
- Public Member Functions inherited from orxonox::Identifiable
 Identifiable ()
 Constructor: Sets the default values. More...
 
virtual ~Identifiable ()
 
ORX_FORCEINLINE voidgetDerivedPointer (unsigned int classID)
 Returns a valid pointer of any derived type that is registered in the class hierarchy. More...
 
template<class T >
ORX_FORCEINLINE T * getDerivedPointer (unsigned int classID)
 Version of getDerivedPointer with template. More...
 
template<class T >
ORX_FORCEINLINE const T * getDerivedPointer (unsigned int classID) const
 Const version of getDerivedPointer with template. More...
 
IdentifiergetIdentifier () const
 Returns the Identifier of the object. More...
 
bool isA (const Identifier *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
template<class B >
bool isA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isA (const Identifiable *object)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isChildOf (const Identifier *identifier)
 Returns true if the object's class is a child of the given type. More...
 
template<class B >
bool isChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a child of the given type. More...
 
bool isChildOf (const Identifiable *object)
 Returns true if the object's class is a child of the given type. More...
 
bool isDirectChildOf (const Identifier *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
template<class B >
bool isDirectChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectChildOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectParentOf (const Identifier *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
template<class B >
bool isDirectParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
bool isDirectParentOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isExactlyA (const Identifier *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
template<class B >
bool isExactlyA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
bool isExactlyA (const Identifiable *object)
 Returns true if the object's class is exactly of the given type. More...
 
bool isParentOf (const Identifier *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
template<class B >
bool isParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
bool isParentOf (const Identifiable *object)
 Returns true if the object's class is a parent of the given type. More...
 
- Public Member Functions inherited from orxonox::Destroyable
 Destroyable ()
 Constructor: Sets the default values. More...
 
virtual ~Destroyable ()
 Destructor: Notifies all DestructionListener (for example weak pointers) that this object is being deleted. More...
 
void destroy ()
 Deletes the object if no strong pointers point to this object. More...
 
void destroyLater ()
 Works like destroy() but doesn't destroy the object until the current tick has ended. More...
 
unsigned int getReferenceCount () const
 Returns the number of strong pointers that point to this object. More...
 
- Public Member Functions inherited from orxonox::ClientConnectionListener
 ClientConnectionListener ()
 Constructor Register the object. More...
 
virtual ~ClientConnectionListener ()
 

Static Public Member Functions

static void executeHelper (const std::string &code, const std::string &mode, bool needsGraphics)
 Helper method that is used to reach this Script object on other clients. More...
 
- Static Public Member Functions inherited from orxonox::BaseObject
static void loadAllEventStates (Element &xmlelement, XMLPort::Mode mode, BaseObject *object, Identifier *identifier)
 Manually loads all event states, even if the class doesn't officially support them. More...
 
- Static Public Member Functions inherited from orxonox::ClientConnectionListener
static void broadcastClientConnected (unsigned int clientID)
 Call clientConnected() on all ClientConnectionListeners. More...
 
static void broadcastClientDisconnected (unsigned int clientID)
 Call clientDisconnected() on all ClientConnectionListeners. More...
 

Private Member Functions

void modeChanged ()
 Sets the mode to the mode specified in this->modeStr_. More...
 
void setMode (ScriptMode mode)
 Sets the mode of the Script. More...
 

Private Attributes

std::string code_
 The code that is executed by this Script. More...
 
bool forAll_
 Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering the Script. More...
 
ScriptMode mode_
 The mode the Script is in. Determines whether the code is executed the normal way or in lua. More...
 
std::string modeStr_
 The mode the Script is in, as a string. Is used for networking purposes. More...
 
bool needsGraphics_
 Whether the code to be executed needs graphics. More...
 
bool onLoad_
 Whether the Scripts code is executed upon loading (creation) of this Script. More...
 
int remainingExecutions_
 The number of remainign executions. -1 denotes infinity. More...
 
int times_
 The number of times the Scripts code is executed at the most. -1 denotes infinity. More...
 

Static Private Attributes

static const int INF = -1
 
static const std::string LUA = "lua"
 
static const std::string NORMAL = "normal"
 Static variables to avoid magic strings. More...
 

Additional Inherited Members

- Protected Member Functions inherited from orxonox::BaseObject
void addEventState (const std::string &name, EventState *container)
 Adds a new event-state to the object. More...
 
EventStategetEventState (const std::string &name) const
 Returns the event-state with the given name. More...
 
- Protected Member Functions inherited from orxonox::Destroyable
virtual void preDestroy ()
 This virtual function is called if destroy() is called and no StrongPtr points to this object. More...
 
- Protected Attributes inherited from orxonox::BaseObject
mbool bActive_
 True = the object is active. More...
 
mbool bVisible_
 True = the object is visible. More...
 
FunctorPtr mainStateFunctor_
 
std::string mainStateName_
 
std::string name_
 The name of the object. More...
 
std::set< std::string > networkTemplateNames_
 
std::string oldName_
 The old name of the object. More...
 

Detailed Description

The Script class lets you execute a piece of code, either the normal way or in lua, through XML.

It can be specified whether the code is executed upon loading (creation) of the object. Additionally the code is executed each time a trigger event comes in. There are three parameters:

Here are two examples illustrating the usage:

<Script code="showGUI QuestGUI" needsGraphics=true />

This would show the QuestGUI opon creation of the object. The mode is normal, not specified here since that is the default, also onLoad is true, also not specified, since it is the default as well. Also needsGraphics is set to true because showGUI needs graphics to work.

<Script code="hideGUI QuestGUI" mode="normal" onLoad="false" needsGraphics=true >
<events>
<DistanceTrigger distance=10 target="Pawn" />
</events>

This would hide the QuestGUI as soon as a Pawn got in range of the DistanceTrigger. The mode is normal, it is specified here, but could be ommitted as well, since it is the default. OnLoad is false, that is why it can't be ommitted. Also needsGraphics is set to true because showGUI needs graphics to work.

Author
Benjamin Knecht
Damian 'Mozork' Frick

Constructor & Destructor Documentation

orxonox::Script::Script ( Context context)

Constructor.

Registers and initializes the object.

orxonox::Script::~Script ( )
virtual

Destructor.

Cleans up.

Member Function Documentation

void orxonox::Script::clientConnected ( unsigned int  clientId)
overridevirtual

Callback that is called when a new client has connected.

Parameters
clientIdThe clientId of the new client that has connected.

Implements orxonox::ClientConnectionListener.

virtual void orxonox::Script::clientDisconnected ( unsigned int  clientid)
inlineoverridevirtual
void orxonox::Script::execute ( unsigned int  clientId,
bool  onLoad = false 
)

Executes the Scripts code for the input client, depending on the mode.

Parameters
clientIdThe Id of the client the Script should be executed for.
onLoadWhether this method is executed as a result of the onLoad parameter being set to true. Default is false.
void orxonox::Script::executeHelper ( const std::string &  code,
const std::string &  mode,
bool  needsGraphics 
)
static

Helper method that is used to reach this Script object on other clients.

const std::string& orxonox::Script::getCode ( ) const
inline

Get the code that is executed by this Script.

Returns
Returns the code that is executed by this Script.
const std::string & orxonox::Script::getMode ( void  )

Get the mode of the Script.

Returns
Returns the mode as a string.
bool orxonox::Script::getNeedsGraphics ( void  )
inline

Get whether the code to be executed needs graphics to work.

Returns
Returns true if the code needs graphic, false if not.
int orxonox::Script::getTimes ( void  )
inline

Get the number of times this Script is executed at the most.

Returns
Returns the number of times this Script is executed at the most. -1 denotes infinity.
bool orxonox::Script::isForAll ( void  )
inline

Get whether the Script executes its code for all players or just for the player triggering the Script.

Returns
Returns true if the code is executed for all players, false if not.
bool orxonox::Script::isOnLoad ( void  )
inline

Get whether this Script is executed onLoad.

Returns
Returns true if this Script is executed onLoad, false if not.
void orxonox::Script::modeChanged ( void  )
private

Sets the mode to the mode specified in this->modeStr_.

This is used internally for networking purposes.

void orxonox::Script::setCode ( const std::string &  code)
inline

Sets the code that is executed by this Script.

Parameters
codeThe code that is executed by this Script.
void orxonox::Script::setForAll ( bool  forAll)
inline

Set whether the code is executed for all players or just for the player triggering the Script.

Parameters
forAllIf true the code is executed for all players.
void orxonox::Script::setMode ( const std::string &  mode)

Sets the mode of the Script.

Parameters
modeThe mode as a string.
void orxonox::Script::setMode ( ScriptMode  mode)
inlineprivate

Sets the mode of the Script.

Parameters
modeThe mode of the Script.
void orxonox::Script::setNeedsGraphics ( bool  needsGraphics)
inline

Set whether the code to be executed needs graphics to work.

Parameters
needsGraphicsTrue if the cde needs graphics to be executed properly.
void orxonox::Script::setOnLoad ( bool  onLoad)
inline

Set whether this Script is executed onLoad or not.

Parameters
onLoadif true the Script is executed onLoad, if false it's not.
void orxonox::Script::setTimes ( int  times)

Set the number of times this Script is executed at the most.

-1 denotes infinity.

Parameters
timesThe number of times to be set.
bool orxonox::Script::trigger ( bool  triggered,
BaseObject trigger 
)

Is called when an event comes in trough the event port.

Parameters
triggeredWhether the event is triggering or un-triggering.
triggerThe object that caused the event to be fired.
Returns
Returns true if successful.
void orxonox::Script::XMLEventPort ( Element &  xmlelement,
XMLPort::Mode  mode 
)
overridevirtual

Creates a port that can be used to channel events and react to them.

Parameters
xmlelementThe element.
modeThe mode.

Reimplemented from orxonox::BaseObject.

void orxonox::Script::XMLPort ( Element &  xmlelement,
XMLPort::Mode  mode 
)
overridevirtual

Method for creating a Script object through XML.

Parameters
xmlelementThe element.
modeThe mode.

Reimplemented from orxonox::BaseObject.

Member Data Documentation

std::string orxonox::Script::code_
private

The code that is executed by this Script.

bool orxonox::Script::forAll_
private

Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering the Script.

const int orxonox::Script::INF = -1
staticprivate
const std::string orxonox::Script::LUA = "lua"
staticprivate
ScriptMode orxonox::Script::mode_
private

The mode the Script is in. Determines whether the code is executed the normal way or in lua.

std::string orxonox::Script::modeStr_
private

The mode the Script is in, as a string. Is used for networking purposes.

bool orxonox::Script::needsGraphics_
private

Whether the code to be executed needs graphics.

const std::string orxonox::Script::NORMAL = "normal"
staticprivate

Static variables to avoid magic strings.

bool orxonox::Script::onLoad_
private

Whether the Scripts code is executed upon loading (creation) of this Script.

int orxonox::Script::remainingExecutions_
private

The number of remainign executions. -1 denotes infinity.

int orxonox::Script::times_
private

The number of times the Scripts code is executed at the most. -1 denotes infinity.


The documentation for this class was generated from the following files: