Changeset 7474 for code/trunk/src/modules/objects/Script.h
- Timestamp:
- Sep 21, 2010, 11:15:44 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/Script.h
r7463 r7474 33 33 34 34 #include <string> 35 #include <vector> 36 35 37 #include "core/BaseObject.h" 38 #include "tools/interfaces/Tickable.h" 39 #include "network/synchronisable/Synchronisable.h" 40 #include "network/ClientConnectionListener.h" 36 41 37 42 namespace orxonox … … 54 59 'code': The code that should be executed. 55 60 'mode': The mode, specifying whether the set code should be executed the normal way ('normal') or in lua ('lua'). Default is 'normal'. 56 'onLoad': Whether the code is executed upon loading (creation) of this object. Default is true.61 'onLoad': Whether the code is executed upon loading (creation) of this object. If this is set the code is executed ofr all players, regardless of the value of parameter 'forAll'. Default is true. 57 62 'needsGraphics': Whether the code needs graphics to be executed or not. Default is false. 63 'forAll': Whether the code is executed for all players each time the Script is triggered or jut for the player triggering the Script. If forAll is false, which is default, the event that triggers the Script must come from a PlayerTrigger. 58 64 59 65 Here are two examples illustrating the usage: … … 77 83 Damian 'Mozork' Frick 78 84 */ 79 class _ObjectsExport Script : public BaseObject 85 class _ObjectsExport Script : public BaseObject, public Synchronisable, public ClientConnectionListener, public Tickable 80 86 { 81 87 public: … … 86 92 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a port that can be used to channel events and react to them. 87 93 88 void trigger(bool triggered); //!< Is called when an event comes in trough the event port. 89 void execute(); //!< Executes the Scripts code, depending on the mode. 94 virtual void tick(float dt); 95 96 bool trigger(bool triggered, BaseObject* trigger); //!< Is called when an event comes in trough the event port. 97 void execute(unsigned int clientId, bool fromCallback = false); //!< Executes the Scripts code for the input client, depending on the mode. 90 98 91 99 /** … … 139 147 { return this->needsGraphics_; } 140 148 149 /** 150 @brief Set whether the code is executed for all players or just for the player triggering the Script. 151 @param forAll If true the code is executed for all players. 152 */ 153 void setForAll(bool forAll) 154 { this->forAll_ = forAll; } 155 /** 156 @brief Get whether the Script executes its code for all players or just for the player triggering the Script. 157 @return Returns true if the code is executed for all players, false if not. 158 */ 159 bool isForAll(void) 160 { return this->forAll_; } 161 162 virtual void clientConnected(unsigned int clientId); 163 virtual void clientDisconnected(unsigned int clientid) {} 164 141 165 private: 142 166 //! Static variables to avoid magic strings. … … 150 174 int times_; //!< The number of times the Scripts code is executed at the most. -1 denotes infinity. 151 175 bool needsGraphics_; //!< Whether the code to be executed needs graphics. 176 bool forAll_; //!< Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering the Script. 177 178 std::string modeStr_; 179 180 std::vector<unsigned int> clientCallbacks_; 181 float counter_; 152 182 153 183 LuaState* luaState_; //!< The LuaState to execute the code in lua. 154 184 int remainingExecutions_; //!< The number of remainign executions. -1 denotes infinity. 185 186 void registerVariables(void); 187 void modeChanged(); 155 188 156 189 /**
Note: See TracChangeset
for help on using the changeset viewer.