Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "pressOrRepeat" choice for event handlers? #3288

Open
klausw opened this issue Mar 16, 2021 · 6 comments
Open

Add a "pressOrRepeat" choice for event handlers? #3288

klausw opened this issue Mar 16, 2021 · 6 comments
Labels
api enhancement New feature or request gameengine

Comments

@klausw
Copy link
Contributor

klausw commented Mar 16, 2021

Is your feature request related to a problem? Please describe.
Currently, there are separate event handler types for "pressed" and "repeat", but it's quite common that the game will want to do the same action on each. The workarounds are to either copy the code, or to wrap it in a function, and both are a bit clunky.

Describe the solution you'd like
Could we get a "onPressOrRepeat" event choice to make this easier?

Additional context
Context: discussion in https://forum.makecode.com/t/a-heart-of-cosines-blocks/6791/3

@jwunderl
Copy link
Member

We kind of have this -- in
image
there's a block to set the delay / interval for repeat, and setting delay to 0 should behave as you want (the functionality is available in js by default / without an extension, and I believe you should be able to set it on a per button basis as well there)

Here's an example: https://makecode.com/_Vvuasy3UXLwD

@klausw
Copy link
Contributor Author

klausw commented Mar 16, 2021

That is useful, but I think that's not quite the same thing. If you want to use buttons for something like cursor control or menu entries, having a nonzero repeat delay is nice since it allows for precise single movements. Forcing the repeat delay to zero wouldn't work well for that use case.

@jwunderl
Copy link
Member

Ah, those are two distinct values; delay is 'how long until it triggers the first time', and interval is 'how long does it wait between triggers of the event'

@klausw
Copy link
Contributor Author

klausw commented Mar 16, 2021

Yes, but unless I'm misunderstanding it, the current sequence is:

  1. onPress
  2. (delay time)
  3. onRepeat
  4. (repeat interval time)
  5. onRepeat
  6. (repeat interval time)
  7. goto 3

That means it's possible to separately configure delay time and interval time, but if you want to have two distinct time values for more precise input, with a longer delay time after the first press, you still need to add separate event handlers for both onPress and onRepeat. Setting the delay time to zero is a workaround if you want to use a single fixed repeat interval, but then you lose the ability to have a longer delay after the first press.

I think configuring the timing is a separate issue from needing distinct event handlers for first press vs repeated press. Or am I missing something?

@jwunderl
Copy link
Member

Ah, so you're looking for

onPress
(delay time)
(repeat interval time)
onRepeat
(repeat interval time)
onRepeat
(repeat interval time)
goto 4

I see, fair enough

@klausw
Copy link
Contributor Author

klausw commented Mar 16, 2021

Not quite, I mean this:

  1. onPress and onPressOrRepeat
  2. (delay time)
  3. onRepeat and onPressOrRepeat
  4. (repeat interval time)
  5. onRepeat and onPressOrRepeat
  6. (repeat interval time)
  7. ...

So an application that wants to take different actions for first press vs repeated press can use the current separate handlers to do so, but if it wants to do the same action for each, it just uses the proposed new onPressOrRepeat handler instead to avoid duplicated handler code. Does this make sense?

If I remember right, key events in other systems typically do have a single event that's triggered for both the first and repeated key presses, so I think it would be natural to have this in Arcade also.

@jwunderl jwunderl added enhancement New feature or request gameengine labels Mar 16, 2021
@abchatra abchatra added the api label Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api enhancement New feature or request gameengine
Projects
None yet
Development

No branches or pull requests

3 participants