Instead of using GetValidWords function twice, do this

The for loops, specially big ones, like loop inside other loops, or lopping inside big N (N = length) ^most of the time. So in this lectuare I decided to remind all students about this point.
What I did, used the GetValidWords(…) function once, assigned the returning value to a paramater.
Then using this paramater to get a word in a random index, without to call it again.

TArray TempWordsList = GetValidWords(Words);
HiddenWord = TempWordsList[FMath::RandRange(0, TempWordsList.Num() - 1)];

Now some of you may say this is not worth it, but what I learned so far in 2 years of coding, is that every line you can make it easier for the cpu/ hardware to run, do it.

A Quick Knowledge: There’s something called “Complications”, in coding, like for example there can be 2 or more solving ways for a problem, one is more easier to run (less run time) than the other.

Search for this topic “Complications” in C++ or whatever and see what do I mean, you can learn a new skills of how to solve problems in a better ways.

Mahdi Abu Hamida, I’m new here, and thanks for the team, for the great way of explaining UE4, I’m glad I found this cource, and good luck for all the students!

2 Likes

We are happy to hear that! Keep up the amazing work!

1 Like

Privacy & Terms