Strange error:

When we were creating a new list of words in ValidWords, my list did something strange: have a look:

You will notice that “accept, account, across” sandwich the rest of the text in the middle.
I am not sure of the reason, and I double checked my code to the code examples.
Here is the code:

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    
    SetupGame();

    PrintLine(TEXT("The number of possible words is %i"), Words.Num());
        PrintLine(TEXT("The Hidden word is: %s."), *HiddenWord);// debug line

    TArray<FString> ValidWords;

    for (int32 Index = 0; Index < 10; Index++)
    {
             
       if (Words[Index].Len() >= 4 && Words[Index].Len() <= 8 )
       {
          ValidWords.Emplace(Words[Index]);
       }
       
       for (int32 Index = 0; Index < ValidWords.Num(); Index++)
       {
            PrintLine(TEXT("%s."), *ValidWords[Index]);
       }
       
    }

You’ve placed the second for loop inside the first for loop. Try placing the the second loop outside and below the first, should fix your issue. Also I believe the strange behavior you’re seeing is because the nested loop is using the same Index int32 variable.

Yes, It was the case, a nested for loop. twice the fun…

Thank you for pointing this out.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms