KeyDown returned as Int
Monkey Forums/Monkey Programming/KeyDown returned as Int
| ||
Hi, is there any particular reason why KeyDown returns an Int instead of a Bool? I'm surprised it's the first time it has come up, but I've just had the following error when trying to store the state of KeyDown in a Bool variable. Error : Cannot convert from Int to Bool. |
| ||
That is strange, but not unexpected. As the mojo code has no return set, it'll return an int in non-strict mode.Function KeyDown( key ) Return device.KeyDown( key ) End Most people are going to use KeyDown like this, so it usually isn't a problem. If KeyDown(KEY_X) ' Do something End I wouldn't say you're off though, that this isn't right. It probably should return boolean instead of an integer. |
| ||
This was also mentioned about TouchDown() here: http://www.monkeycoder.co.nz/Community/posts.php?topic=994 Mark agreed that the "down" functions should probably return a Bool instead of an Int. (Returning Int makes more sense for the "hit" functions.) |
| ||
Most people are going to use KeyDown like this, so it usually isn't a problem. Yeah, that's probably why I've not seen it before. I can't think of the proper name for it, but I'm making a middle man kind of control system so that bool variables for moving/aiming can be set by the keyboard, touch controls or the joypad. |
| ||
The way monkey deals with input could generally be improved. For instance MouseDown() doesn't only get you a positive response during the frame it got called for the first time like in many other languages where they differ between Mouse, MouseDown, MouseHit. Instead it's true every frame which forces you to keep track of these things on your own. It's more work and confusing when you're jumping between different languages. |
| ||
mousedown and mousehit have always worked like that and no-one else complains about them |
| ||
There may be other functions with similar names in some languages. But you really need an async function that tells you when the mouse is down now. Use MouseHit() to tell if it's been clicked since the last update. |
| ||
@slenkar Actually that's a great argumentation. @Gerry Quinn Let's put it this way, monkey's implementation needs more work to be done, depending on what you're trying to achieve, and it isn't common whilst also offering no benefit on top. |
| ||
it isn't common whilst also offering no benefit on top Well, there is a benefit to BRL in not having to write/support a more complete input library. You could argue that it's impossible to predict how people would want to abstract across the mouse/touch interfaces so it's best not to try. For my own stuff I wrap the mojo input module in a pseudo-event system that provides KEY_DOWN/KEY_UP events as well as other nice-to-haves like MOUSE_DRAG info. |
| ||
In my opinion Input is one of the core features which i would try to get done as good as possible. Btw. i remember that the first problem a friend of mine, i once suggested monkey to, had was that his code was flipping through his menus due to the unexpected behaviour of MouseDown. |
| ||
I don't find the Monkey system unusual. Mojo isn't really event driven except at the most basic level, so why would I expect MouseDown() to tell me anything other than whether the mouse is down? Generally the function called during every update starts: If MouseHit( MOUSE_LEFT ) > 0 |
| ||
For what it's worth, I'm happy with the way the mouse/key functions work, except the Down functions should really return a bool. |