SA-MP Forums Archive
BUG with SelectTextDraw and OnPlayerKeyStateChange - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: BUG with SelectTextDraw and OnPlayerKeyStateChange (/showthread.php?tid=430719)



BUG with SelectTextDraw and OnPlayerKeyStateChange - DartakousLien - 14.04.2013

look

pawn Код:
if(oldkeys & KEY_WALK) {
    if(GetPVarInt(playerid,"problema")==10034) {
        SCMPOW(playerid,-1,"released");
        DeletePVar(playerid,"problema");
    }
    else {
        SCMPOW(playerid,-1,"release");
        CancelSelectTextDraw(playerid);
    }
}
else if(newkeys & KEY_WALK) {
    SCMPOW(playerid,-1,"press");
    SetPVarInt(playerid,"problema",10034);
    SelectTextDraw(playerid,COR_VERMELHO);
}
in server, i press ALT and i get

press
released

and when release ALT, it's bugged! all keys are bugged

but if i try like this
pawn Код:
if(oldkeys & KEY_WALK) {
    SCMPOW(playerid,-1,"release");
    CancelSelectTextDraw(playerid);
}
else if(newkeys & KEY_WALK) {
    SCMPOW(playerid,-1,"press");
    SelectTextDraw(playerid,COR_VERMELHO);
}
in server i press ALT and i get

"press"
"release"
"press"
"release"
"press"
"release"
"press"
"release"
"press"
"release"
.....

please, fix it!


Re: BUG with SelectTextDraw and OnPlayerKeyStateChange - MP2 - 15.04.2013

1. Use a better indentation style. It's almost impossible to see which block of code is paired with which if/else statement.

2. Use the defines PRESSED() etc. from the wiki https://sampwiki.blast.hk/wiki/OnPlayerK...heck_for_a_key


Re: BUG with SelectTextDraw and OnPlayerKeyStateChange - DaRk_RaiN - 15.04.2013

I'd conferm that some keys are bugged such as KEY_CROUCH.


Re: BUG with SelectTextDraw and OnPlayerKeyStateChange - Basssiiie - 15.04.2013

I've never had any problems with the keys. Make sure you are using the callback correctly.

If you're pressing KEY_CROUCH, then pressing KEY_SPRINT and then releasing KEY_CROUCH: the callback will be called three times. Do note that.

With the above example newkeys and oldkeys should be the following values:
KEY_CROUCH pressed: newkeys = 2, oldkeys = 0.
KEY_SPRINT pressed: newkeys = 10 ( 2 + 8 ), oldkeys = 2.
KEY_CROUCH released: newkeys = 8, oldkeys = 10.
KEY_SPRINT released: newkeys = 0, oldkeys = 8.
If you look here, you'll see that 2 is the value of KEY_CROUCH and 8 is the value of KEY_SPRINT.

If you have this in your script:
Код:
if (newkeys & KEY_CROUCH) return print("test");
And you apply the above example, then it'll print "test" in the console twice.

The PRESSED, HOLDING and RELEASED macro's on the Wiki should filter this correctly.


Re: BUG with SelectTextDraw and OnPlayerKeyStateChange - DartakousLien - 15.04.2013

Quote:
Originally Posted by MP2
Посмотреть сообщение
1. Use a better indentation style. It's almost impossible to see which block of code is paired with which if/else statement.

2. Use the defines PRESSED() etc. from the wiki https://sampwiki.blast.hk/wiki/OnPlayerK...heck_for_a_key
1. i use a perfect indentation, but here, can't appers a corret indentation in first line of code ...
2 . i tryed it, but not work!

thanks


Quote:
Originally Posted by Basssiiie
Посмотреть сообщение
I've never had any problems with the keys. Make sure you are using the callback correctly.

If you're pressing KEY_CROUCH, then pressing KEY_SPRINT and then releasing KEY_CROUCH: the callback will be called three times. Do note that.

With the above example newkeys and oldkeys should be the following values:
KEY_CROUCH pressed: newkeys = 2, oldkeys = 0.
KEY_SPRINT pressed: newkeys = 10 ( 2 + 8 ), oldkeys = 2.
KEY_CROUCH released: newkeys = 8, oldkeys = 10.
KEY_SPRINT released: newkeys = 0, oldkeys = 8.
If you look here, you'll see that 2 is the value of KEY_CROUCH and 8 is the value of KEY_SPRINT.

If you have this in your script:
Код:
if (newkeys & KEY_CROUCH) return print("test");
And you apply the above example, then it'll print "test" in the console twice.

The PRESSED, HOLDING and RELEASED macro's on the Wiki should filter this correctly.
i have tryed it too, but, the problem continues ... i try (newkeys & KEY_CROUCH), (newkeys == KEY_CROUCH) PRESSED(KEY_CROUCH)
but, the problem continues, i think is a bug in SelectTextDraw function
yes, i made it by another form, but i think it funny so! and want use so, but i can't

thanks for all


Re: BUG with SelectTextDraw and OnPlayerKeyStateChange - MP2 - 16.04.2013

Quote:
Originally Posted by DartakousLien
Посмотреть сообщение
1. i use a perfect indentation, but here, can't appers a corret indentation in first line of code ...
Your indentation isn't WRONG (but it's far from perfect) - it's very hard to read.

Compare:


pawn Код:
if(oldkeys & KEY_WALK) {
    if(GetPVarInt(playerid,"problema")==10034) {
        SCMPOW(playerid,-1,"released");
        DeletePVar(playerid,"problema");
    }
    else {
        SCMPOW(playerid,-1,"release");
        CancelSelectTextDraw(playerid);
    }
}
else if(newkeys & KEY_WALK) {
    SCMPOW(playerid,-1,"press");
    SetPVarInt(playerid,"problema",10034);
    SelectTextDraw(playerid,COR_VERMELHO);
}



pawn Код:
if(oldkeys & KEY_WALK)
{
    if(GetPVarInt(playerid,"problema")==10034)
    {
        SCMPOW(playerid,-1,"released");
        DeletePVar(playerid,"problema");
    }
    else
    {
        SCMPOW(playerid,-1,"release");
        CancelSelectTextDraw(playerid);
    }
}
else if(newkeys & KEY_WALK)
{
    SCMPOW(playerid,-1,"press");
    SetPVarInt(playerid,"problema",10034);
    SelectTextDraw(playerid,COR_VERMELHO);
}
It's a LOT easier to see the individual code blocks when the braces ({ & }) are on their own lines.