TArray: Quest(ion)


Can you put cod into your TArrays so as to call up elements of your code, randomly or not?

I could see how this could be useful for TripleX should one want random encounters while exploring rooms prior to the actual main puzzle itself.

I’m not quite sure what you mean. Could you give an example?

In the TArray, at least as we have learned it using it for the HiddenWordList, could you place a multi-line code (like a long string) or function in each element where the words are, and then call up these longer codes from their respective elements?

In the case of the Triple X, put in some encounter, descriptive or some function, that can be called up? So that if the player does A, code from element 0 will be called up (a function) or if B, some other thing?

I hope this clarifies my question.

It made it more confusing to be honest :sweat_smile:.

Though I think you would mean something like this?

TArray<FString> Messages
    TEXT("You should try harder"),
    TEXT("You're doing great"),
    TEXT("You need practice"),

FString Message = FMath::RandHelper(Messages.Num());
// Message == random word from Messages


I am probably confusing terms.

Yes, something like that.

Also, as an example, say you are on a world map and you have a chance of triggering a random special encounters requiring player input, could there be a check that calls up an array of random encounter (functions maybe?); below is an example of what I mean, even if it is completely wrong:

[0] void UBCCartridge :: RandomEncounterCall1 // calls up a flock of cows encounter
[1] void UBCCartridge::  RandomEncounterCall2 // Calls up old Tom ecnounter
[2] void UBCCartridge :: RandomEncounterCall3 // Calls up Wolves encounter
[3] void UBCCartridge::  RandomEncounterCall4 // Calls up mysterious Cave encounter

Thus if element 0 is randomly called, the player runs into a flock of cows and all the code associated with it comes up.

Yes you could do it that way but storing member functions in an array is not the way to go for that. Instead I would create a function like so

void UExample::RandomEncounter()
    int32 RandNum = FMath::RandRange(1, 4);
    case 1:
    case 2:
    case 3:
    case 4:

Ah yes, the old Switch. I used that in TripleX at the end. That makes sense.

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

Privacy & Terms