Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Today I learned: contraptions' hidden widgets can leak out

A topic by Screwtapello created 10 days ago Views: 139 Replies: 7
Viewing posts 1 to 2
(+4)

I’m not sure if this is a bug or Just The Way It Works, but it surprised me so I figured I’d talk about it and let other people know.

Let’s say we make a new contraption. It’s going to need to store some data, so we’ll stick a big field outside the visible area. We haven’t put any widgets inside the visible area, so let’s just paint the background red so we can see where the contraption is:

image.png

We can plonk that contraption in the middle of a card and see that it is the only widget there, there’s nothing else around it:

image.png

But when we switch to Interact mode, and move the mouse cursor to the right of the red box, it turns into the text-editing I-beam cursor! And if we drag around, we can select text and get access to the formatting menu!

image.png

This confused me for quite a while, but the solution is simple: in the Prototype editor, select the field and make it Locked:

image.png

Then the user won’t be able to accidentally interact with it. Making the field “Show None” might also work, but that makes it harder to test the contraption interactively in the prototype editor.

I have hit a snag. I have a contraption I want to be able to trigger with a keypress, so I put a secret button inside it, and when you set the shortcut attribute on the contraption, it sets the shortcut attribute on the secret button. This works pefectly - keypresses outside the contraption trigger the secret button inside it.

Unfortunately it also triggers the behaviour described above - clicking on the card where the secret button would be also triggers it, even if that area is supposed to be some other widget. And unlike the above workaround, setting the secret button to “Locked” or “Show None” deactivates the shortcut behaviour.

I suppose the workaround to the workaround would be to remove the shortcut feature from the contraption, and just add buttons to the card directly… and hide them by moving them off the side of the screen, rather than with “Show None”.

(+1)

I'm not sure yet whether the overall behaviour around widgets in the outside bits of contraptions is intended or not, but I do know that one of the design considerations on Decker is that decks should still be usable on touch-only devices, and not require keyboard input. So I think the intent is to not be able to have keypresses without a corresponding clickable button.

Hiding a button off screen might work as a workaround though if you really want to do it. But if you're targeting web decker and don't mind diving into the danger zone, there's also functionality in the forbidden library to read keypresses directly from javascript.

To be clear, I do have a clickable button, it’s just that I’m using a canvas so I can get the click event as well as the release event. I figured that, like regular buttons, it would be nice to support shortcuts as well as clicks.

I’m not currently targeting Web Decker, but it’s cool that getting key-down events is at least sometimes possible. Thanks for letting me know!

(+2)

I suspect the "hide offscreen" workaround may work for buttons inside contraptions too tbh, which keeps things a bit neater. If you set the position manually using the console you should be able to position it to be sure it's offscreen even if the contraption is up against a corner in the outside world.

It looks like it does! Thanks!

I had hoped I could check "card"=typeof card.parent to see if contraption was being used on a card (in which case, the button needs to be moved out of the way) or if the prototype was being edited (in which case, leave the button where it is so we can edit it). Unfortunately it seems like a prototype’s parent is always some card, even if that card does not contain any contraptions.

Still, if I really need to, I can still bring the button back on-screen by setting its position in the Listener.

(+2)

You can also use the Widgets -> Order... menu option to select from a text list of widgets (including any that may be hiding offscreen) so you can edit its script and properties without needing to actually see it

Developer(+2)

If you really want to distinguish a prototype from a contraption, you could check the typeof "card" rather than "card.parent". There are other visible api differences, like contraption.def and prototype.widgets, but most of the time it's desirable for them to seem the same during prototype editing.