Download

New to coding and got some noob questions.

Ok so my problem with coding is this. I need to know what some thing is and what it is used for. so like how to use it proper and how not to use it. So for the very first one is Void. And here is an example of code with void in it

// Called when the game starts or when spawned
void AMyFirstClass::BeginPlay()
{
Super::BeginPlay();

}

// Called every frame
void AMyFirstClass::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );

}

Void is something that doesn’t return anything

Beginplay() - when you start the game what ever is in the beginplay() will run at the start of the game or when spawned

Tick() - what ever is inside of the tick() will be ran every frame

Reading the comments above it really tells you what it all does “//Called when the game starts or spawned” “//Called every frame”

You should first learn some programming theory and how stuff works in programming before jumping into UE4 c++ coding.

What you asked is the basis of programming. A function must contain a return type (at least in c++) it can be anything. As rapiidzz901 stated, void doesn’t return anything. for example int will return a whole number, float will return a floating number, FVector will return a vector.

Here’s some tutorials.

Best regards,
YoungWolf

Another thing i thought i would add is this https://www.udemy.com/unrealcourse/learn/v4/overview
This is what i started when learning c++. He first goes over basic c++ and then be moves onto ue4 c++ there is also a lot of challenges and forums with active people and a lot of help.
If you have a bit of money spare i would 100% recommend this. Probably the best tutorial i have ever have and seen.
He also reefers back a few videos so that you dont forget what you learnt 2-3videos ago.

Dude no way. Don’t waste your money at the time that Udemy course was $30 dollars and I got my money back. Rarely for me I ever received substantial help on the forums. SO from my perspective I tell you this. You must find someway to learn almost everything to code like at a college level. Maybe you’ll get help in the forums. But his videos I don’t recommend, I stopped when he said just guess which function to pick and see if it makes sense and etc. If you’re using C++ you must also learn software engineering so you’ll learn fancy terms that the api talk about… Trusted me I wasted my time on bad books and finally got on track. You rather learn to use your skills then just copy somebody. But whatever floats your boat and good luck.

for me it was £10 and you have 30days to refund your money so its worth a shot see if you like it or not

whatever floats your boat…I just wouldn’t dare tell anybody you’ll be a game developer by just learning syntax and copying him to some extent. If you’re very knowledgeable in programming you may pick up a few tricks besides that nawh.

I suppose yeah it may just be best to take a course on c++ or just dive straight in and work things out through the documents and forums. All depends on how you learn

Yeah I made that mistake…=( trying to look at unreal tutor videos… But I wised up now I understand everything in the api. It’s all about being pointed in the right direction. Have to be a computer scientist first.

I wouldn’t just smack down his approach. Sure, it’s tedious, but his question implies that he dived right in and at least understood something.
Let him go at it and then decide himself when he needs a more structured approach to learning. In fact, doing a course on something is easier once you tried that something.

I’d just suggest doing the course early, rather than late, to avoid acquiring bad habits. Your first attempts at code will look atrocious to you, once you actually learned how to code.

Anyway, for the OP question:
A function is a set of instructions that can be inserted at any time into a piece of code.
For example, if you want to compare two numbers, you call the function for comparing two numbers.
Most of the time it follows a syntax like “Compare(Number1, Number2)”. The actual comparison operator in C++ is ==, but that’s beside the point right now.
As you can see in the example, you input two numbers and then… Yeah, how do you get the result?
By doing stuff like this:



bool result; //Declares a boolean (true/false) variable called result
result = Compare(3, 5); //sets result to the result of the Compare function

This is where the “void” thing comes into play. “Compare” used bool instead of void, which means that the return value will be a boolean.
This means you can use the function like a number. You can set the value of a variable to the result of the function.

Have you seen the instruction “return XYZ;” in any of the functions you looked at?
Once that instruction is called, the function ends and its output value is set to the value that is written after return.


int PassThrough(int Pass) {
return Pass;
}

Is a valid function. It doesn’t do anything useful, though. Writing “x = 1” and “x = PassThrough(1)” would be the same.

Functions that use void are called procedures. They don’t output anything, but rather do something. In your example, it’s used for Events. Tick is an Event that is called once per tick (internal time unit of the game) and BeginPlay happens once after the actor with that Event is created in the game world. (There’s also the constructor, which describes how the actor is created. Constructors are an object-oriented concept that you should look up once you got the basics down)

There’s also keywords like virtual and static, but I suggest you learn how to Google this kind of question. Seriously, half the point of having a second monitor as a programmer is to have Google open while you code.