Solved Is there some way to check if a button is not being held?

Question that is answered or resolved.

NONAME01150

New member
Is there some way to check if said button (ex:attack3) is not being held instead of checking if said button was released?
 
Yes, you need to acquire the inverse of held case.
Ex:
C:
void iRKey = playerkeys(0, 0, "attack3"); // player 1's attack3 key held

The inverse would be !playerkeys(0, 0, "attack3") which is player 1's not holding attack3 state.
 
Hi, would this work then?
Code:
void main()
{
void entity = getlocalvar("self");
int Anim = getentityproperty(entity, "animationID");
int PlayerIndex = getentityproperty(entity, "playerindex");
int NotKeyHold = !getplayerproperty(PlayerIndex, "keys");

if(anim == openborconstant("ANI_FREESPECIAL5"))
{
 if(NotKeyHold & openborconstant("FLAG_ATTACK3"))
 {
  performattack(entity, openborconstant("ANI_FREESPECIAL6"), 0);
 }
}
}
I'm trying to use entity's "script" to check the entity's anim and jump from the firing loop (freespecial5) to the stop firing anim (freespecial6).
 
Ignoring variable name typo there, I'm afraid that when the script is run, it will immediately change from FREESPECIAL5 to FREESPECIAL6 if no key is pressed by respective player. getplayerproperty(PlayerIndex, "keys") acquires key held state for any key not just Attack3.
 
On this topic, I'm designing a grapple/struggle system and am trying to accept player input to switch an enemy attack animation. The code below currently doesn't trigger:

Code:
@script

    void self = getlocalvar("self");
    void target = getlocalvar("Target" + self);
    int PlayerIndex = getentityproperty(target, "playerindex");
    int keyhold = getplayerproperty(PlayerIndex, "keys");

    if(frame>26){
        if(target!=NULL() & keyhold){
           
        changeentityproperty(self, "animation", openborconstant("ANI_Follow9"));
           }
    }
@end_script

I'm guessing it's because PlayerIndex doesn't properly reference the player, but I'm not sure how to fix it. This script is run by an enemy, and is supposed to switch to another animation if the player presses a button. Any ideas?
 
Last edited:
Hmmm... this line:
C:
void target = getlocalvar("Target" + self);

Unless, the local variable has been filled with something, it will be empty and thus can't refer to any player.
Try changing it into something like this:
C:
void target = getentityproperty(self, "opponent");

This will acquire latest opponent instead.
 
No luck. Script crashes.
Any other ideas on how to identify player button pushes that don't use the Target or Opponent property?
 
I think the script crashes because you tried to acquire opponent's index before it's confirmed if there's an opponent or not.
I've tried fixing the script and it goes like this:
C:
  if(frame>26){
    void self = getlocalvar("self");
    void target = getentityproperty(self, "opponent");

    if(target){
      int PIndex = getentityproperty(target, "playerindex");
      int KeyHold = getplayerproperty(PIndex, "keys");

      if(KeyHold!=0){
        changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW9"));
      }
    }
  }
Any other ideas on how to identify player button pushes that don't use the Target or Opponent property?

Well, it's possible to acquire player's button press directly, however respective player might not be in grabbed state. IOW it would be easier to acquire opponent first then his/her player index later.
 
I think what you're missing is the key flag.

Code:
@script

    void self = getlocalvar("self");
    void target = getlocalvar("Target" + self);
    int PlayerIndex = getentityproperty(target, "playerindex");
    int keyhold = getplayerproperty(PlayerIndex, "keys");

    if(frame>26){
        if(target!=NULL() && keyhold & openborconstant("FLAG_ATTACK2")){
        
        changeentityproperty(self, "animation", openborconstant("ANI_Follow9"));
           }
    }
@end_script

Or..

Code:
@script

    void self = getlocalvar("self");
    void target = getlocalvar("Target" + self);
    int PlayerIndex = getentityproperty(target, "playerindex");
    int keyhold = getplayerproperty(PlayerIndex, "keys");

    if(frame>26){
        if(target!=NULL() && keyhold & openborconstant("FLAG_MOVEUP")){
        
        changeentityproperty(self, "animation", openborconstant("ANI_Follow9"));
           }
    }
@end_script

It allows you to hold a given specific player key you want.

The one with two ampersands (&&) means AND. I think one ampersand (&) operator is like a required need to something. I don't know how one & operator is used other than the conjunction of "keys"/"newkeys"/"releasekeys" and the key flags.

 
Last edited:
Oh interesting; that does indeed appear to work. The & and && in general are bit-wise and logical AND (at least if it behaves like C++), but the openbor engine is definitely a case of "you don't know what you don't know", particularly in terms of internally defined variables. Thanks for that.
 
Back
Top Bottom