Simple Toggle but with mouse_status

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

Simple Toggle but with mouse_status

Postby A1rookie » Mon Nov 25, 2019 12:20 pm

Hi all,
I wanted to create a simple Toggle :
If i press mouse Button 4 (not mapped in the k&m input translator), it starts to hold down r2 until i press mouse Button 4 again.
I tried it with a simple bool R2=!R2 but it's switching around very quickly and so its Not working.

Thanks for your help

Best regards
User avatar
A1rookie
Staff Sergeant
Staff Sergeant
 
Posts: 13
Joined: Mon Sep 10, 2018 5:26 pm

Re: Simple Toggle but with mouse_status

Postby Scachi » Mon Nov 25, 2019 2:14 pm

Search for "mouse_events" in the online resource

or with custom code: store the current mouse_status result of that button into a flag and change r2 only on a new press.
Code: Select all
#include <mouse.gph>
 
bool mb4 = FALSE;
bool r2 = FALSE;
 
main {
    if (mouse_status(MBUTTON_4) && !mb4)
    {
        r2 = !r2;
        mb4 = TRUE;
        printf("toggled: %d", r2);
    }
    if (!mouse_status(MBUTTON_4)) mb4 = FALSE;
}
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: No registered users and 131 guests