Word/Words/ValidWords...so many Words

If I am honest, with all of the different pieces of this all named some variation of “Word” I find myself having to go back and walk through how we arrived at certain outcomes.

For instance, I have a variable of Word and a variable of Words. Sometimes I would just like a quick way to see what is populated in my Array “Words”. I am hoping to simplify this…is there a way I can pull that out, without having to run through the outcome of several steps of code in my head?

I feel like the optional Predicate lesson will help with this. I am going to upgrade my engine to 4.26 and go through that piece and we’ll see what happens at that point.

You could give them different names?

I did but I would have to rethink all these variables and document it and I really don’t want to do that.

Does this mean that there is not easy way, programmatically, to quickly see what an Array is holding?

Depends if you are talking about the content of the variable or the type of the variable.

== Type ==
For the type, is this variable Words a FString, TArray, int32, etc… most popular IDE’s have something to find the declaration. I use Rider (for Unreal Engine) and I can hit “Ctrl - B” and it will go to the declaration or usages. I think Visual Studio might have something similar.

== Content ==
If you mean what content or theoretical content is this variable holding at any given time, that is a little more complex. Using a debugger is one way to see what content is stored at any given time and most popular IDE’s can do it (Debug Unreal Engine Project | JetBrains Rider), but this takes a little setup work. Another method is printing out information to a console or log (UE_LOG for instance) to display at certain points in the code to verify the code is doing what you think. Something like:

for(int32 i = 0; i < Words.Num(); i++)
{
    UE_LOG(LogTemp, Log, TEXT("i (%i)"), i, *Words[i]);
    // do something with words...
}

int32 RandWord = FMath::RandRange(0, Words.Num() - 1);
CurrentWord = Words[RandWord];

UE_LOG(LogTemp, Log, TEXT("Current Word: %s"), *CurrentWord);

== Notes ==
It is typical for a programmer to have to keep some sort of mental model of what is going on. This is what makes naming variables very important. Too long or too complex, then it may be easy to forget. Too short, then it may be difficult to determine what it is.

However things like keeping functions short and purposeful and making code easily readable helps for anyone after you or for yourself years later. However, too short of a function may affect performance if data is passed around a lot needlessly. It is a balancing act of sorts.

Also this is where Unit Tests help as well. Unit Tests validate the functions you write in small chunks so you can be sure each function does what you expect.

Hope that helps.

3 Likes

Yes, I was referring to what is currently contained within an Array. The type is easy.

Usually, if I was doing this myself I would have a much more thorough design laid out with objects defined and inheritance mapped out to make it easier to follow rather than just hoping I remember which object or function does which. The architecture side is fine…the coding side is what I need to figure out.

Trying to remember these things is not my strong suit. LOL

1 Like

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

Privacy & Terms