MCPcopy
hub / github.com/4ian/GDevelop / replace

Method replace

GDJS/Runtime/scenestack.ts:246–274  ·  view source on GitHub ↗

* Start the scene in `options.sceneName`, replacing the one currently being played. * If `options.clear` is set to true, all running scenes are also removed from the stack of scenes. * * @param options Contains the scene name and optional external layout name to instantiate. * @p

(
      options: ReplaceSceneOptions | string,
      deprecatedClear?: boolean
    )

Source from the content-addressed store, hash-verified

244 * @param deprecatedClear Deprecated, use `options.clear` instead.
245 */
246 replace(
247 options: ReplaceSceneOptions | string,
248 deprecatedClear?: boolean
249 ): gdjs.RuntimeScene | null {
250 const clear =
251 deprecatedClear || typeof options === 'string' ? false : options.clear;
252 const newSceneName =
253 typeof options === 'string' ? options : options.sceneName;
254
255 this._throwIfDisposed();
256 if (!!clear) {
257 // Unload all the scenes
258 while (this._stack.length !== 0) {
259 let scene = this._stack.pop();
260 if (scene) {
261 this._unloadSceneAndPossiblyResources({ scene, newSceneName });
262 }
263 }
264 } else {
265 // Unload the current scene
266 if (this._stack.length !== 0) {
267 let scene = this._stack.pop();
268 if (scene) {
269 this._unloadSceneAndPossiblyResources({ scene, newSceneName });
270 }
271 }
272 }
273 return this.push(options);
274 }
275
276 /**
277 * Return the current gdjs.RuntimeScene being played, or null if none is run.

Calls 4

_throwIfDisposedMethod · 0.95
pushMethod · 0.95
popMethod · 0.45

Tested by 1

testCompletionsFunction · 0.64