Function Last Chance

Hello Guys,

That’s my implementation, when player come to the last lives console will print the first and then last letter of the hidden word.

Header file:

struct LastChance
{
	TCHAR FirstLetter;
	TCHAR LastLetter;
};
//other code....
public:
LastChance TipsLetter(const FString& Parola) const;

Call in cpp file:

 if(Vite == 1)
    {
      LastChance LettereFinal = TipsLetter(ParolaSegreta);
      PrintLine(TEXT("Ultima Vita, Suggerimento Finale!!\nLa parola inizia con: %c\nFinisce con:%c"), LettereFinal.FirstLetter,LettereFinal.LastLetter);
      return;
    }

Function:

LastChance UBullCowCartridge::TipsLetter(const FString& Parola) const
{
    LastChance Letters;

    for (int32 i = 0; i < Parola.Len(); i++)
    {
        if (i == 0) 
        {
            Letters.FirstLetter = Parola[i];
        }
        if (i == Parola.Len() - 1)
        {
            Letters.LastLetter = Parola[i];
        }
    }
    return Letters;
}

Is there a better or more performing way to achieve the same result or did I do a good job?

thanks a lot

Well first off good job with trying to extend the game and then posting about it :).

With that said, it’s got a lot of redundancies. It can be done with just

if (Vite == 1)
{
    PrintLine(TEXT("Ultima Vita, Suggerimento Finale!!\nLa parola inizia con: %c\nFinisce con:%c"), ParolaSegreta[0], ParolaSegreta[ParolaSegreta.Len() - 1]);
    return;
}

I also imagined this solution I just preferred to practice with the struct. :slight_smile: thank you so much

1 Like

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

Privacy & Terms