Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -2161,6 +2161,32 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 2160 unmodified lines | ||
| 2161 | 2161 | }, forceRedownload); |
| 2162 | 2162 | } |
| 2163 | 2163 | |
| 2164 | +/**jsdoc | |
| 2165 | + * Triggered when the script starts for a user. | |
| 2166 | + * <p>Note: Can only be connected to via <code>this.preload = function (...) { ... }</code> in the entity script.</p> | |
| 2167 | + * <table><tr><th>Available in:</th><td>Client Entity Scripts</td><td>Server Entity Scripts</td></tr></table> | |
| 2168 | + * @function Entities.preload | |
| 2169 | + * @param {Uuid} entityID - The ID of the entity that the script is running in. | |
| 2170 | + * @returns {Signal} | |
| 2171 | + * @example <caption>Get the ID of the entity that a client entity script is running in.</caption> | |
| 2172 | + * var entityScript = (function () { | |
| 2173 | + * this.entityID = Uuid.NULL; | |
| 2174 | + * | |
| 2175 | + * this.preload = function (entityID) { | |
| 2176 | + * this.entityID = entityID; | |
| 2177 | + * print("Entity ID: " + this.entityID); | |
| 2178 | + * }; | |
| 2179 | + * ); | |
| 2180 | + * | |
| 2181 | + * var entityID = Entities.addEntity({ | |
| 2182 | + * type: "Box", | |
| 2183 | + * position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5 })), | |
| 2184 | + * dimensions: { x: 0.5, y: 0.5, z: 0.5 }, | |
| 2185 | + * color: { red: 255, green: 0, blue: 0 }, | |
| 2186 | + * script: "(" + entityScript + ")", // Could host the script on a Web server instead. | |
| 2187 | + * lifetime: 300 // Delete after 5 minutes. | |
| 2188 | + * }); | |
| 2189 | + */ | |
| 2164 | 2190 | // since all of these operations can be asynch we will always do the actual work in the response handler |
| 2165 | 2191 | // for the download |
| 2166 | 2192 | void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success , const QString& status) { |
| @@ -2345,6 +2371,13 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 178 unmodified lines | ||
| 2345 | 2371 | processDeferredEntityLoads(entityScript, entityID); |
| 2346 | 2372 | } |
| 2347 | 2373 | |
| 2374 | +/**jsdoc | |
| 2375 | + * Triggered when the script terminates for a user. | |
| 2376 | + * <p>Note: Can only be connected to via <code>this.unoad = function () { ... }</code> in the entity script.</p> | |
| 2377 | + * <table><tr><th>Available in:</th><td>Client Entity Scripts</td><td>Server Entity Scripts</td></tr></table> | |
| 2378 | + * @function Entities.unload | |
| 2379 | + * @returns {Signal} | |
| 2380 | + */ | |
| 2348 | 2381 | void ScriptEngine::unloadEntityScript(const EntityItemID& entityID, bool shouldRemoveFromMap) { |
| 2349 | 2382 | if (QThread::currentThread() != thread()) { |
| 2350 | 2383 | #ifdef THREAD_DEBUGGING |