I tried adding a c++ Function Library to my blueprint project but when I try to compile i get this error:
11>BPFL_PokerHelper.gen.cpp.obj: Error LNK2019 : riferimento al simbolo esterno "public: enum EPokerHand __cdecl UBPFL_PokerHelper::EvaluatePokerHandC(class TArray<int,class TSizedDefaultAllocator<32> > const &)" (?EvaluatePokerHandC@UBPFL_PokerHelper@@QEAA?AW4EPokerHand@@AEBV?$TArray@HV?$TSizedDefaultAllocator@$0CA@@@@@@Z) non risolto nella funzione "public: static void __cdecl UBPFL_PokerHelper::execEvaluatePokerHandC(class UObject *,struct FFrame &,void * const)" (?execEvaluatePokerHandC@UBPFL_PokerHelper@@SAXPEAVUObject@@AEAUFFrame@@QEAX@Z) 11>BPFL_PokerHelper.gen.cpp.obj: Error LNK2019 : riferimento al simbolo esterno "public: class FString __cdecl UBPFL_PokerHelper::PokerHandToStringC(enum EPokerHand)" (?PokerHandToStringC@UBPFL_PokerHelper@@QEAA?AVFString@@W4EPokerHand@@@Z) non risolto nella funzione "public: static void __cdecl UBPFL_PokerHelper::execPokerHandToStringC(class UObject *,struct FFrame &,void * const)" (?execPokerHandToStringC@UBPFL_PokerHelper@@SAXPEAVUObject@@AEAUFFrame@@QEAX@Z) 11>BPFL_PokerHelper.gen.cpp.obj: Error LNK2019 : riferimento al simbolo esterno "public: int __cdecl UBPFL_PokerHelper::DetermineWinnerC(class TArray<enum EPokerHand,class TSizedDefaultAllocator<32> > const &)" (?DetermineWinnerC@UBPFL_PokerHelper@@QEAAHAEBV?$TArray@W4EPokerHand@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z) non risolto nella funzione "public: static void __cdecl UBPFL_PokerHelper::execDetermineWinnerC(class UObject *,struct FFrame &,void * const)" (?execDetermineWinnerC@UBPFL_PokerHelper@@SAXPEAVUObject@@AEAUFFrame@@QEAX@Z) 11>UnrealEditor-InvaderTest.dll: Error LNK1120 : 3 esterni non risolti
I searched online but every solution I tried didn’t go well and I can’t seem to undertand what’s wrong with my code.
The header file is the following:
`// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
include “Kismet/BlueprintFunctionLibrary.h”
include “CoreMinimal.h”
include “Containers/Array.h”
include “BPFL_PokerHelper.generated.h”
UENUM(BlueprintType)
enum class EPokerHand : uint8 {
HighRoll UMETA(DisplayName = “High Roll”),
Pair UMETA(DisplayName = “Pair”),
DoublePair UMETA(DisplayName = “Double Pair”),
Tris UMETA(DisplayName = “Tris”),
Straight UMETA(DisplayName = “Straight”),
FullHouse UMETA(DisplayName = “Full House”),
Poker UMETA(DisplayName = “Poker”),
All UMETA(DisplayName = “All”)
};
/**
*
*/
UCLASS()
class INVADERTEST_API UBPFL_PokerHelper : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Funzione per determinare il punteggio della mano di poker.
* @param Dice Array di 5 valori che rappresentano i risultati dei dadi.
* @return Il punteggio calcolato (EPokerHand).
*/
UFUNCTION(BlueprintCallable, Category = “PokerGame”)
EPokerHand EvaluatePokerHandC(const TArray& Dice);
/**
* Funzione per convertire un punteggio di poker in stringa.
* @param Hand Il punteggio di poker da convertire.
* @return La rappresentazione testuale del punteggio.
*/
UFUNCTION(BlueprintCallable, Category = "PokerGame")
FString PokerHandToStringC(EPokerHand Hand);
/**
* Funzione per determinare il vincitore dato un array di mani di poker.
* @param Hands Array contenente i punteggi dei giocatori (max 4).
* @return Indice del vincitore (0-based). -1 in caso di errore.
*/
UFUNCTION(BlueprintCallable, Category = "PokerGame")
int32 DetermineWinnerC(const TArray<EPokerHand>& Hands);
};`
While the cpp file is the following:
// Fill out your copyright notice in the Description page of Project Settings.
include <BPFL_PokerHelper.h>
// Funzione per determinare il punteggio della mano di poker
EPokerHand EvaluatePokerHandC(const TArray& Dice) {
if (Dice.Num() != 5) {
UE_LOG(LogTemp, Error, TEXT(“Sono necessari esattamente 5 dadi.”));
return EPokerHand::HighRoll;
}
// Conta le occorrenze di ogni valore di dado
TMap<int32, int32> Counts;
for (int32 Die : Dice) {
Counts.FindOrAdd(Die)++;
}
// Verifica per la scala (1-5 o 2-6)
TArray<int32> SortedDice = Dice;
SortedDice.Sort();
if (SortedDice == TArray<int32>{1, 2, 3, 4, 5} || SortedDice == TArray<int32>{2, 3, 4, 5, 6}) {
return EPokerHand::Straight;
}
// Analizza i conteggi
bool bHasPair = false;
bool bHasTris = false;
int32 PairCount = 0;
for (const auto& Elem : Counts) {
int32 Count = Elem.Value;
if (Count == 4) {
return EPokerHand::Poker;
}
else if (Count == 3) {
bHasTris = true;
}
else if (Count == 2) {
bHasPair = true;
PairCount++;
}
}
if (bHasTris && bHasPair) {
return EPokerHand::FullHouse;
}
else if (bHasTris) {
return EPokerHand::Tris;
}
else if (PairCount == 2) {
return EPokerHand::DoublePair;
}
else if (bHasPair) {
return EPokerHand::Pair;
}
// Se nessuna altra mano, ritorna HighRoll
return EPokerHand::HighRoll;
}
// Funzione per stampare il punteggio della mano come stringa
FString PokerHandToStringC(EPokerHand Hand) {
switch (Hand) {
case EPokerHand::HighRoll: return TEXT(“High Roll”);
case EPokerHand::Pair: return TEXT(“Pair”);
case EPokerHand::DoublePair: return TEXT(“Double Pair”);
case EPokerHand::Tris: return TEXT(“Tris”);
case EPokerHand::Straight: return TEXT(“Straight”);
case EPokerHand::FullHouse: return TEXT(“Full House”);
case EPokerHand::Poker: return TEXT(“Poker”);
case EPokerHand::All: return TEXT(“All”);
default: return TEXT(“Unknown”);
}
}
// Funzione per determinare il vincitore
int32 DetermineWinnerC(const TArray& Hands) {
if (Hands.Num() > 4) {
UE_LOG(LogTemp, Error, TEXT(“Un massimo di 4 giocatori sono ammessi.”));
return -1;
}
// Ranking delle mani
static const TArray<EPokerHand> HandRanking = {
EPokerHand::HighRoll,
EPokerHand::Pair,
EPokerHand::DoublePair,
EPokerHand::Tris,
EPokerHand::Straight,
EPokerHand::FullHouse,
EPokerHand::Poker,
EPokerHand::All
};
// Trova l'indice della mano di punteggio piĂą alto
int32 WinnerIndex = -1;
int32 HighestRank = -1;
for (int32 i = 0; i < Hands.Num(); ++i) {
int32 CurrentRank = HandRanking.IndexOfByKey(Hands[i]);
if (CurrentRank == INDEX_NONE) {
UE_LOG(LogTemp, Error, TEXT("Mano non valida fornita."));
return -1;
}
if (CurrentRank > HighestRank) {
HighestRank = CurrentRank;
WinnerIndex = i;
}
}
return WinnerIndex;
}