Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

view event fired every frame?

A topic by Louisono created Dec 27, 2023 Views: 147 Replies: 1
Viewing posts 1 to 2

Hi, I have created a view function in a card script to run some logic once the card is navigated to. The documentation about events says:

Target: card, Event: view, Argument: None, When: The card is navigated to, or the user enters interaction mode.

But the function seems to be called every single frame. The card doesn't contain any widget (as I would like to populate the card procedurally from the script), so I don't think an "animated" widget could fire view events. According to the docs the view event should be fired punctually instead of continuously, is that correct or am I misinterpreting it? What am I missing here?

Developer

Several things can cause a single view[] event to be pumped to a card:

  • Exiting editing tools/switching to Interact mode
  • Exiting the Listener
  • Dismissing a modal dialog, including an alert[] box
  • Initially opening a deck
  • Navigating to a card with go[], by setting deck.card, or manually using navigation keyboard shortcuts (some of which can be intercepted in navigate[])

That last one is a little tricky, since a phrase like "go[card]" will effectively schedule a view[] event for the next frame. Thus, one possible idiom for driving continuous animation on a card looks like:

on view do
 
 # some animation code...
 go[card]
end

Unhandled events "bubble": if there's no "on view do ... end" in an animated widget's script, the event will be offered to the card, and then the deck in turn.

There is a known issue in v1.36 in which contraptions can (erroneously) bubble their internal events to the containing card, which can lead to some mischief, though it doesn't sound like the problem you're describing is related. This is already patched in the version of web-decker on beyondloom.

Because there are many things other than explicitly "visiting" a card which can fire a view[] event, it is generally not a good idea to use it for code which is intended to run exactly once. There's some discussion of that problem in this thread which might be relevant.