MoscowModder's Forum Posts

  • Update 2: I found a very recent addon that serves this exact purpose. Thanks for uploading it, MasterPose!

    construct.net/en/make-games/addons/1531/dom-side

  • Update: I found a way to do this - I just attach an event listener to the document in my init script, which catches tab/escape keypresses.

    // Intercept Tab/Esc keys (this only works if web worker mode is disabled)
    if(globalThis.hasOwnProperty("document")) {
    	document.addEventListener("keydown", e => {
    		if(e.key == "Tab" || e.key == "Escape")
    			e.preventDefault();
    	});
    }
    else {
    	console.warn("Running on a web worker; can't intercept tab/esc events!");
    }

    The only limitation is that this doesn't work in web worker mode because web workers don't have access to the document object.

    I don't suppose there's a way to inject this snippet into the main thread so that it runs once before the game engine even starts?

  • I am trying to publish a multi-platform game (Windows/Webview2; Linux/CEF; macOS/WKWebView).

    My pause control is mapped to the escape key. On Windows & Linux, this is fine. However, in the macOS version, the esc press will exit fullscreen.

    Is there some way to intercept the keypress events so that the escape key is only used in-game and doesn't un-fullscreen the browser?

    Or do I just need to change my keybinds on mac to avoid this issue?

  • Oh, that's good to know! I wasn't sure whether that was the case.

    I tried waiting for the "On save complete" event to fire before going to the other layout, so it seems as if saving isn't the problem.

    I've also been digging further into the devtools debugger for error I'm getting. It seems as if `runtime._DoChangeLayout()` is failing inside `runtime._ReleasePendingInstances()`, such that `runtime._isLoadingState` never gets changed back to `false`.

    Furthermore, after the error happens, all of the instances getting released in this loop `for (const e of this._instancesPendingRelease) e.Release()` have `e._objectType == null`. Obviously since the code is a) not mine, and b) minified, I'm not sure what to make of this.

    I also don't know how I'd go about posting a bug report since I can't get this error to reproduce in a minimal project, and I don't know how I can find what specific thing in my project might be causing this (that would need to be recreated in the minimal project).

  • Darn, I was afraid of that.

    Does anyone know why they don't support the async functionality and "Wait for previous actions"?

  • In case anyone just so happens to recognize the error I'm dealing with, here's the most common offending stacktrace.

    This sporadically happens when I'm returning from the menu (yes, there are some instances in the layout with the Tween behavior).

    runtime.js:1 [Construct] Failed to load state from storage: Error: cannot call while loading state - wait until afterload event at C3.Runtime.GetInstanceByUID (runtime.js:1:49355) at C3.TweenTrackState.GetInstance (trackState.js:1:2663) at C3.TweenState.GetInstance (tweenState.js:1:1636) at C3.TweenState._TweenTrigger (tweenState.js:1:10306) at C3.TweenState.Release (tweenState.js:1:580) at s.Instance.ReleaseTweens (runtime.js:1:7451) at s.Instance.ReleaseAndCompleteTweens (runtime.js:1:7684) at s.Instance.Release (runtime.js:1:1063) at C3.BehaviorInstance.Release (behaviorInstance.js:1:538) at C3.Instance.Release (instance.js:1:1836)

  • I have a weird bug I'm experiencing, but I don't quite know how I'd go about reproducing it for the official bug submission process, so I'm starting with some theories about what I'm doing that might be wrong.

    I have a settings menu in my game that can be accessed from any layout. Returning from this menu must put you right back where you came from, so I use the built-in save/load functions to restore the state of the level you were in previously.

    Here are what my functions look like:

    Function goToMenu(string menu)

    • Save game to slot "menu"
    • Take snapshot of canvas (this is so the settings menu appears on top of the level)
    • Wait for previous actions to complete
    • Go to layout menu

    Function returnFromMenu()

    • Load game from slot "menu"
    • (Other async stuff)
    • Wait for previous actions to complete

    So my question is this - stuff like "Take snapshot" and my "other async stuff" are async actions that can be waited on with "Wait for previous actions to complete". But, can I guarantee that the game will be fully saved by the time goToMenu() ends?

    I'm aware of the "On save complete" action, but I really wish I could use the async features to make it easy to tell which save event is which (I also use the same save system for in-level checkpoints).

  • Hmm, thanks for that. I suppose in a way it's similar to my own implementation, except it can happen synchronously. I'll keep that in mind.

  • I use the built in save/load functionality for mid-game checkpoints. I also use a Dictionary and JSON object, both of which get written to a file, for game settings & permanent progress.

    Whenever I load a checkpoint, the state of my settings & save data also roll back. This means that if the player made any permanent progress, or changed a setting, these get undone.

    I am able to work around this by reloading these 2 things from the disk on load, but these are causing some order-of-operations headaches for me.

    Is there some way to simply prevent these objects from being written to/read from the saved state on save/load, similar to the No save behavior? Sadly, these 2 plugins don't allow me to add behaviors to them.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ah, nice! Thanks rhg1968!

  • DiegoM - Hmm. It's not as elegant as I might like, but I suppose that could work.

    Perhaps some day I'll learn the addon SDK and develop my own plugin for this.

  • Yeah, that sounds pretty similar to what I have.

    Using the layout name in the function call sadly won't help me because I also have a Pause menu that appears in most layouts. Some layouts have both the pause menu and another menu.

    I might swap out my own equivalent to your OnKeyPressed functions from callbacks to functions for consistency. I felt that might take a small performance hit, but it could be worth it.

  • Unfortunately, signals don't take parameters, which I rely on in many places.

  • Right. I am not doing this for repeatable bits of code. That's what I use the native Functions feature for.

    I'm only using the old Function plugin because it just so happens to provide exactly the functionality I need for callbacks.

    If we had custom events on objects, I could replace a lot of this. But I can't.

    I'm not asking how functions work. I am asking if there is anything else out there that could do exactly (or approximately) what I am doing now.

  • Okay, how about this case then: control inputs.

    My game supports both keyboard and gamepad inputs. All of these inputs are customizable with an in-game menu.

    I have 2 kinds of checks, similar to the built-in Keyboard & Gamepad plugins:

    * inputDown(control): Checks if the given input is being held down. Implemented with a native function. Checked with an expression.

    * inputPressed(control): Event called when this button is pressed. Implemented with the Functions plugin.

    For example, here's the code in my Controls event sheet that fires these events:

    And here's the code in my Menus event sheet that listens to keyboard input while a menu cursor is active:

    And here's the code in my Player event sheet that also listens to some of the same events:

    So basically, when I press a keyboard/gamepad button, the controls module sends out a callback that a playable character or a menu cursor or something else might possibly listen for. I can't make a single function out of all the possible things that might happen when you press a button.