How would you get an input, and make it affect something?

Hello! I’m currently in the early stages of learning C++, and I have got something to move on a constant loop. What i was wondering, was if you could press a button, and the loop could, for example, speed up. This would help me out in the long run, so I’d appreciate an answer :slight_smile:

How do you control the speed of your constant loop right now? You can change it by clicking a button or something after adding some input actions in your project settings.

After that you can use virtual function SetupPlayerInputComponent to bind specific function in your code to specific button in your keyboard.

In the following tutorial you can see a step-by-step guide how to add WASD movement in a project.

Well, this is where i got to, a failed compile. Is it because I have the setupplayerinput component twice, and should i put it in private or public? Another question is the input functions section. There doesn’t seem to be any reference to growing in the script besides here, so maybe i followed the tutorial wrong?

Thank you for answering a rush of questions from a newbie programmer :slight_smile:

protected section has to be inside the class definition. In your case it’s outside and that’s why it’s not compiling. Also you cannot have the same method declaration twice so do not add SetupPlayerInputComponent twice, one is enough. :slight_smile:

Well, I did something write, but now theres a new problem with the Amypawn. Would i just change this to the name of my actor? Besides that, The build log says I require permission for something, what would this be for?

Thank you for the continued help!

Try AMyPawn : public APawn rather than AMyPawn ; public APawn.

You cannot use semicolon after public APawn because you have just told the compiler that you are going to define your own class called AMyPawn so you cannot stop there.

Try the following:

class UNREALCPP_API AMyPawn : public APawn

    // rest of your code goes here
    // ...
    virtual void BeginPlay() override;

Okay, that worked! Now all thats left is a syntax error with {} brackets on the class!
Thank you so much for all the help :slight_smile:

Oh, okay! That worked! Thank you :slight_smile:
So i guess you cant use an empty class as the engine will not know what to do with it?

Okay, for some reason my ue4 is 4.22.3 now, and my old project was just 4.22, and now its not compiling. And when I tried to compile from the source, I got errors as it would not use the unreal terms in it, so I can’t open my work anymore. Do you know why this would occur?