🔸언리얼 C++ ▪ FMath::RandRange(1, 45); 1과 45 사이에서 랜덤한 수를 뽑아줌
▪ GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("로또 번호: %s"), *LottoNumbersStr)); 블루프린트의 print string 노드와 같은 역할 -1은 새로 생성(양수 값은 인덱스로 사용 가능 -> 같은 번호일 경우 덮어씀) 5.f는 지속 시간 FColor는 폰트 색깔 FString은 출력 내용
▪Visual Studio 주석 단축키 안 먹힐 땐 자판 배열 확인하기 ⁉️ 상기시키기
▪ 반복문에서 arr[i]는 *(arr + i)와 동일
▪ int* ptr = arr; 이렇게 선언되었다고 했을 때 ptr에 산술연산 적용 시 arr[i]와 ptr[i](*(ptr + i))는 다를 수 있음
▪ 동적 메모리 관리를 하거나 재할당을 하는 경우에는 포인터 사용 아니면 참조자 사용
▪ 상수 참조자 -> 읽기 전용으로 접근
1️⃣ C++ 개념 강의
🔹UE_LOG를 활용한 로또번호생성기 구현
#include "lottoNum.h"
// Sets default values
AlottoNum::AlottoNum()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AlottoNum::BeginPlay()
{
Super::BeginPlay();
TArray<int32> Numbers;
for (int i = 0; i < 6; ++i) {
int randNum = FMath::RandRange(1, 45);
!Numbers.Contains(randNum) ? Numbers.Add(randNum) : --i;
}
UE_LOG(LogTemp, Warning, TEXT("Lotto Nubmers: %d, %d, %d, %d, %d, %d"), Numbers[0], Numbers[1], Numbers[2], Numbers[3], Numbers[4], Numbers[5]);
}
// Called every frame
void AlottoNum::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}