Hey! I am trying to use an Array and an Enum to create a collectables system, that looks a bit less “programmy”. So this is the array I am trying to use:
USTRUCT()
struct FCollectableID
{
GENERATED_USTRUCT_BODY()
FString Name;
int ID;
bool isThisType;
};
UCLASS()
class ACollectable : public AActor
{
GENERATED_UCLASS_BODY()
//Collectable Identification
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = Stats)
TArray<FCollectableID> PUidentification;
}
So what I am trying to do is create an array with which I can easily select the type of powerup that the Actor holds. I am sending the power up via this function:
void ACollectable::GiveCollectable(class AFPSCharacter* pl)
{
if (pl)
{
pl->ApplyPowerUp(PUamnt, PUidenfication->ID?);
}
}
The problem is, I dont have any experience with Arrays and don’t know how to code it so that the game finds the unit in the array that has “isThisType” as true. I also wanted to ask a question about enums that I thought closly linked to this question. I have created one in my character class, for the powerups:
UENUM(BlueprintType) //"BlueprintType" is essential specifier
namespace EPowerups
{
//256 entries max
enum Type
{
Armor,
Health,
Stamina
};
}
How could I get access to these, so that I could do the following:
void AFPSCharacter::ApplyPowerUp(int32 amnt, int32 PUid)
{
if (PUid == Health)
{
plHealth = FMath::Clamp(plHealth += amnt, 0, plMaxHealth);
FString curHealth = FString::FromInt(plHealth);
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, curHealth);
}
}
Sorry if this is a pretty long question, but I thought it was pretty important for me to fully understand Unreal Engine 4 C++.