How do I use Boolean to active a key ONLY when another key has been pressed?

Hi, new to coding, so I’ve been following videos and Boolean seems to be the way to go but anyways I can’t seem to find one that fully helps with my issue, I have a horse and It’s got walk, trot, canter, and gallop, and for gallop I want it to only be triggered when I press X BUT only when shift is being held, so when it runs I can hold shift, and then press X, and it doesn’t just start galloping when I press x by itself, also would there be a way to toggle X so that even when I stop moving if I press Shift it will stay in gallop as it needs to be toggled on and off.

Unsure of how many questions I can ask here.

Also for my trotting or in human terms jogging, is there a way I can keep my horse in trot even after it’s galloped, because when I move and press Z to trot it works fine and I can stop and move again it will go back into trot, but when I press shift to go faster and then stop, it makes me go back into walk, please help and thank you!

WASD(or others) = walk directions
Z pressed = enter trot
Z released = cancel trot
Shift pressed = enter canter or gallop
Shift released = cancel canter or gallop
canter or gallop overrides trot
during Shift pressed: X pressed = switch between canter and gallop

Am I right?

Yes for shift, but trot I want it to toggle, so I don’t want to have to hold Z but just press it and then press it again when I want to come out of trot, same with X I want to press it and if I stop moving it will remain on till I turn it off, so only shift will be one that needs to be held, sorry I’m not good at explaining :sweat_smile:

WASD(or others) = walk directions
Z pressed = toggle variable “bIWantToTrot“
Shift pressed = set variable “bIWantToCanterOrGallop“ = true
Shift released = set variable “bIWantToCanterOrGallop“ = false
X pressed = if “bIWantToCanterOrGallop“ toggle variable “bCanterOrGallop“

Enum EMyState = Walk, Trot, Canter, Gallop
EMyState GetState() =
if(bIWantToCanterOrGallop) return bCanterOrGallop ? Gallop : Canter;
if(bIWantToTrot) return Trot;
return Walk;

Am I right again?

um, yes I think, I don’t understand coding words yet I’m still very new to this, but I’m gonna assume this is right.

Hope it helps.

ah I’m nearly done, but what is the output that you used with the “M” as I can’t seem to put words in the return nodes, or the ‘select’ where you have canter and gallop, and thank you so much I really do appreciate this, I may have to ask you for help again when I run into an issue, but again thank you so so so much

ah never mind I’ve figured it out! going to test it out now

Do you mean Enumeration? It can enumerate states, like Walk, Trot…

yes I couldn’t find it at first, but I have, but um it doesn’t seem to be working, Unsure on what I’ve done wrong

Hello @0DaStallion1 ,
Welcome to the forum! It’s great that you’re getting into the world of programming and Blueprints. It can be frustrating at times, but it’s definitely not impossible. If something doesn’t work right away, don’t worry,it’s part of the learning process. Take a breather, try again, and keep experimenting.

The code you were given might work, but I’d recommend taking a bit more time to understand the basics before moving forward. Since you mentioned you’re just starting out, it’s best to go step by step and get a clear understanding of how Booleans and Branch nodes work.
Here’s a quick explanation of each one:

Boolean:

this is a variable type that can only have two possible values: True or False. It’s used to check things like whether something is active or inactive, whether a character is jumping, or if a certain condition is met.

Branch:

this node is used to make decisions based on a Boolean value. When executed, it checks if the condition is True or False and sends the execution flow to the corresponding output.

I recommend watching a few videos that explain these concepts with simple examples and also checking the official documentation, which covers them in detail.
Branches & Booleans
Flow Control

Another thing that can really help you while testing your logic is using Print Strings and Breakpoints:

Print String:

displays messages on the screen while the game is running. It’s useful to check if something is being executed or to see the value of a variable. If nothing appears, it means that part of the flow didn’t run.

Breakpoints:

these are markers you can place on Blueprint nodes to pause execution and inspect what’s happening step by step.

With these tools, you’ll get a much clearer idea of how your code flows and easily spot when something isn’t working as expected.
If you have any questions, don’t hesitate to come back and ask on the forum.
Hope it helps!

okay thank you

1 Like

Seems correct, you should handle the rest of the code in Tick, e.g. update animations according to MyState