Problem with the array char inside the game Bulls n Cows

Help, I get a strange lecture of the character array and I don’t know why. It compiles and doesn’t show an error.

Here is a picture of how it appears in the game:

image

And here is my code:

// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"

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

    SetupGame(); 

    PrintLine(TEXT("La palabra secreta es: %s."), *HiddenWord); // Debug Line
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{



    if (bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else // Checking PlayerGuess
    {
        ProcessGuess(Input);
        
    }
}

void UBullCowCartridge::SetupGame()
{  
    // Welcoming player
    PrintLine (TEXT("Muuuuuy bienvenida sea usted!"));
    
    HiddenWord = TEXT("cafe"); 
    Lives = HiddenWord.Len();
    bGameOver = false; 

    PrintLine (TEXT("Adivina la palabra de %i letras"), HiddenWord.Len());
    PrintLine(TEXT("\nTe queda %i vidas"), Lives);
    PrintLine (TEXT("Escribe una palabra y \npresiona ENTER para continuar")); // Prompt PlayerGuees

    const TCHAR HW[] = TEXT("mota");
    PrintLine(TEXT("Primera letra de la palabra secreta es: %c"), HiddenWord[0]); // Print "c"
    PrintLine(TEXT("La cuarta letra de HW es: %a"), HW[2]); // Print letter "a"
}

void UBullCowCartridge::EndGame()
{
    bGameOver = true;
    ClearScreen();
    PrintLine(TEXT("\nPresiona Enter para jugar de nuevo"));
}

void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (Guess == HiddenWord) // Order doesn't matter
    {
        PrintLine (TEXT("Correcto"));
        EndGame();
        return;
    }

    // Check if Isogram
    // if (!IsIsogram) 
    // {
    //     /* code */
    //     PrintLine(TEXT("No hay letras repetidas.\nIntenta de nuevo."));
    // }

    if (Guess.Len() != HiddenWord.Len())
    {
        PrintLine(TEXT("La palabra tiene %i letra/s"), HiddenWord.Len());
        PrintLine(TEXT("Intenta de nuevo. \nTe quedan %i vida/s"), Lives);
        return;
    }

    //Remove Life
    PrintLine(TEXT("Perdiste una vida."));
    --Lives;
    
    if (Lives <= 0)
    {
        PrintLine(TEXT("Ya no te quedan vidas."));
        PrintLine(TEXT("La palabra secreta era: %s"), *HiddenWord);
        EndGame();
        return;
    }

    // Show the player Bulls and Cows
    PrintLine(TEXT("Intenta de nuevo.\nTe quedan %i vida/s"), Lives);

}

If you’re talking about 0x0.000…blah. Then that is the double representation of that character as you have used %a here.

%c is for characters.

1 Like

:sweat: Thank you!!! I hadn´t noticed the type-o :eyes:

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

Privacy & Terms