.Num Outside of (Words)

I just want to know why in the printline for the number of valid words that the proper syntax is PrintLine(TEXT("The number of valid words is: %i."), GetValidWords(Words).Num());

instead of GetValidWords(Words.Num()));

You’re wanting to display how many valid words there are, and GetValidWords checks the array of all possible words and returns only the ones that are valid. You can breakdown what is happening by looking at it this way.

TArray<FString> ValidWords = GetValidWords(Words); //Get array of valid words
int ValidWordCount = ValidWords.Num() //Get the number of valid words in the array, or the size of the array
PrintLine(TEXT("The number of valid words is: %i."), ValidWordCount);

PrintLine(TEXT("The number of valid words is: %i."), GetValidWords(Words).Num()); Does everything in that example in a single line.

Trying to pass in Words.Num() would cause a compiler error as you would be trying to pass an integer when the function is expecting something else.

1 Like