playMaker

Author Topic: Problem with KEY DOWN / MOUSE DOWN and such [SOLVED]  (Read 7627 times)

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Problem with KEY DOWN / MOUSE DOWN and such [SOLVED]
« on: February 25, 2013, 03:38:26 AM »
OK I want to make a FSM where I check the status of a key, and if the user is holding it pressed, I want to add torque to an self.

It's all in a single object, a cube.
Please see the enclosed screenshots.

This is not working.

I tried the same with KEY because I would associate the torque to key press but it's the same story: GET KEY does not work, GET KEY DOWN works.

But I don't want the user to impulse with each click, I want to know when the key is being hold down!

I can't get this to work, anybody has a clue about this?




« Last Edit: February 25, 2013, 11:48:40 AM by megmaltese »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3883
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Problem with KEY DOWN / MOUSE DOWN and such
« Reply #1 on: February 25, 2013, 04:07:13 AM »
Use Get Key Up to exit the Torque state.

That way you'll apply torque as long as the key is down.

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: Problem with KEY DOWN / MOUSE DOWN and such
« Reply #2 on: February 25, 2013, 04:28:10 AM »
Not working.
I think there is some bug.
The functions which take care of watching if a key is being held down are not working, they don't fire up at all.
GET KEY DOWN and GET KEY UP work, GET KEY does not.
GET MOUSE BUTTON DOWN and GET MOUSE BUTTON UP work, GET MOUSE BUTTON does not.

Or wait, maybe I can't understnd how GET KEY works.

Here is how it works in my mind:

1) I GET KEY value and put it in a boolean, let's call it BOOL
2) I check the status of the boolean
3) if BOOL is true, then I fire up the event that adds torque to the object, if BOOL is false nothing happens
4) after torque is added, automatically get back to the CheckKey state

This should be the most straightforward use of the function I think, but maybe there are some complexities more that had to be added to make it work?
« Last Edit: February 25, 2013, 04:54:53 AM by megmaltese »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3883
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Problem with KEY DOWN / MOUSE DOWN and such
« Reply #3 on: February 25, 2013, 10:56:51 AM »
I'll look into Get Key. But why not just use Get Key Down and Get Key Up? It's much simpler - you don't need to store and check a boolean, you just send events.

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: Problem with KEY DOWN / MOUSE DOWN and such
« Reply #4 on: February 25, 2013, 11:48:11 AM »
Hey I solved as you said, much more clean and cool, thank you very much  ;D
Dunno why it didn't come to my mind... guess I have to get back into the coding mental state... I was coder many years ago...  :'(

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Problem with KEY DOWN / MOUSE DOWN and such [SOLVED]
« Reply #5 on: February 25, 2013, 02:29:57 PM »
Hey that's cool! being a not-a-programmer myself it is a little tricky sometimes to find ways to do the things you want it to do.

that said, a method that i've been using which helps with these kinds of things is a "monitor" FSM system... in it i tell it what keys to watch for and to be sending via "Set fsm *variable*" to the FSMs i'm using these actions for (it's helping me pare down extraneous code since my game has a LOT of fsms made and some are, unfortunately, a little redundant so i've been working to clean it up.)

once there, if you're using a boolean, you can approach it a couple ways... you can have in the actions you're using to apply these torque things to have a bool-test in there that's firing off every frame (it seems to be a cheap action in terms of resources used) or a "*variable* has changed" action... from there you can wire it up however you like... you can have it go through a testing state, directly fed to the other states or whatever you need.

that said, it looks like you've resolve it so if you are able, maybe post a screenshot? i'm sure you're not going to be the last person that will come up against something like this and it might help those in the future if you have something visual since some people learn better by seeing it directly whereas some learn better while reading text. just my two cents, really... *thumbs up*

PolyMad

  • Sr. Member
  • ****
  • Posts: 412
    • View Profile
Re: Problem with KEY DOWN / MOUSE DOWN and such [SOLVED]
« Reply #6 on: February 25, 2013, 03:34:32 PM »
So here are the screenshots, it's very easy and it should also use a bit less CPU because you only check the key once at down and once at up.

So in the first state I only check if the button has been pressed, in that case I go to the other state, where the torque is added at every frame.
Only if the key is released I get back to the initial state, very easy.
I am so ashamed I didn't think to this before... feel really stupid :D

I only put it on a cube just for the heck of it, now that I know how to make it work I'm going to make a car or something else  ;D

Anyway, the GET KEY command really seems not working, or there's some structure to set up that I don't know.