script running inconsistently

GPC2 script programming for Titan Two. Code examples, questions, requests.

script running inconsistently

Postby davebruno » Mon Feb 18, 2019 10:48 am

Can anyone tell me why this really simple code would be inconsistent?

For now I want it simply to change the led colour from red to green when I push 'E'

It works but only randomly, maybe 50% of the time..

Code: Select all
#include <keyboard.gph>
#include <display.gph>
#include "light_k.gph"
#include <mouse.gph>
 
init{
  mousemapping();
  keymapping();
}
int mode;
 
main {
  mouse_passthru();
  key_passthru();
 
    if (mode == 0) {
        set_light('G');
        }
 
    if (mode == 1) {
        set_light('R');
        }
 
            if ((key_status(KEY_E)) && (mode == 0)){
            mode = 1;
            }
 
    else if (key_status(KEY_E) && (mode == 1)) {
            mode = 0;
            }
 
    }
User avatar
davebruno
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat Feb 16, 2019 1:34 pm

Re: script running inconsistently

Postby Scachi » Mon Feb 18, 2019 10:51 am

key_status will return true as long as you hold down the key, not only in the moment you press the key.
So it will do =1, =0, =1, ... to your variable as long as you press the key.
Take a look at my answer in your other post.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: script running inconsistently

Postby davebruno » Mon Feb 18, 2019 11:04 am

Scachi wrote:key_status will return true as long as you hold down the key, not only in the moment you press the key.
So it will do =1, =0, =1, ... to your variable as long as you press the key.
Take a look at my answer in your other post.

Got it working, thanks a lot :)
User avatar
davebruno
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat Feb 16, 2019 1:34 pm

Re: script running inconsistently

Postby davebruno » Mon Feb 18, 2019 11:37 am

Scachi wrote:key_status will return true as long as you hold down the key, not only in the moment you press the key.
So it will do =1, =0, =1, ... to your variable as long as you press the key.
Take a look at my answer in your other post.

Actually its still running inconsistent,

Now it switches fine until other keys are pushed, so for example when I run the below it works while tapping E but if I hold W and tap E it doesn't work, any idea why that would happen?

Code: Select all
#include <keyboard.gph>
#include <display.gph>
#include "light_k.gph"
#include <mouse.gph>
#define KEYS_TO_MONITOR_MAX 1 // set to the max number of keys you need
#include "xkeys.gph"
uint8 KEYE;
 
init{
  mousemapping();
  keymapping();
KEYE =xkeys_add(KEY_E);
}
int mode;
int NavState;
 
main {
  mouse_passthru();
  key_passthru();
 
    if (mode > 1) {
        mode = 0;}
 
    if (mode == 0) {
        set_light('G');
        }
 
    if (mode == 1) {
        set_light('R');
        }
 
            if (xkeys_event_active(KEYE)) {
            mode = mode + 1;
            }
 
 
    }
User avatar
davebruno
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat Feb 16, 2019 1:34 pm

Re: script running inconsistently

Postby Scachi » Mon Feb 18, 2019 12:13 pm

bug in my xkeys header, fixed it. please download it again.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: script running inconsistently

Postby davebruno » Mon Feb 18, 2019 12:27 pm

Scachi wrote:bug in my xkeys header, fixed it. please download it again.


Sweet, thank you! :smile0202:
User avatar
davebruno
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat Feb 16, 2019 1:34 pm

Re: script running inconsistently

Postby davebruno » Sat Apr 27, 2019 5:24 pm

Scachi wrote:bug in my xkeys header, fixed it. please download it again.



Yo man, I just changed to a different mouse and I now cannot map its buttons to letters, have you made a mouse equivalent to xkeys at all?

I'm running into the same issues as before..

Thanks,

Dave
User avatar
davebruno
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Sat Feb 16, 2019 1:34 pm

Re: script running inconsistently

Postby Scachi » Sat Apr 27, 2019 9:41 pm

davebruno wrote:
Scachi wrote:bug in my xkeys header, fixed it. please download it again.

Yo man, I just changed to a different mouse and I now cannot map its buttons to letters, have you made a mouse equivalent to xkeys at all?
No, I have none for mouse.
I am not playing with mouse or keyboard..I use some self made device in addition to a default ps4 controller that i can assign keypresses to its buttons. This is what I have created the xkeys header for. That the header is useful for real keyboard too is just a glitch. :wink:

I'm running into the same issues as before..
what are "the same issues" ?
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany


Return to GPC2 Script Programming

Who is online

Users browsing this forum: Majestic-12 [Bot] and 40 guests