Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
I am struggling with pointers to basic data types like ints
Post Flair (click to view more posts with a particular flair)
Post Body

So I'm working on a game with a weapon system. Each weapon has its own type of ammo. I want to create a pointer variable that, instead of having a value in and of itself, it instead points to the int for the active weapon's ammo. Here are my variables.

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeaponStats")
int shotgunAmmo = 10;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeaponStats")
int rocketAmmo = 3;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeaponStats")
int* ActiveAmmo;

I'd ideally set the pointer to link to the ammo types like this:

void ATopDownCharacter::SwitchWeapon(TEnumAsByte<Weapon> WeapToSwitchTo) {
WeapEnum = WeapToSwitchTo;

switch (WeapToSwitchTo)
{
case Weapon::Pistol:
fireRate = fRatePistol;
PrintScreen("switched to normal");
ActiveAmmo = 0;
break;

case Weapon::Shotgun:
fireRate = fRateShotgun;
PrintScreen("swithc to spread");
ActiveAmmo = &shotgunAmmo; //active ammo refers to shotgun ammo
break;

case Weapon::Rocket:
fireRate = rRateRocket;
PrintScreen("swithc to rocket");
ActiveAmmo = &rocketAmmo; //active ammo refers to rocket ammo
break;

default:
break;
}
}

This is so I can write more efficient code for stuff like displaying the remaining ammo for the current weapon (bind a widget to ActiveAmmo instead of doing a switch statement on the current active weapon) or make updating ammo values easier.

void ATopDownCharacter::UpdateAmmo(int AmmoAmnt)
{
  ActiveAmmo  = AmmoAmnt; //This would change whatever is currently set as active ammo by the inputted amount 
  return;
}

However, I get an error at my definition of the ActiveAmmo pointer, stating

Inappropriate "*" on variable of type "int32", cannot have exposed pointer to this type

I have no clue what to do at this point. Am I just fundamentally misunderstanding the use cases of pointers? I've been able to declare pointers for stuff like StaticMeshComponents with no issues, so I don't really get what the difference is between them and a simple integer.

Author
Account Strength
100%
Account Age
6 years
Verified Email
Yes
Verified Flair
No
Total Karma
9,894
Link Karma
5,368
Comment Karma
4,452
Profile updated: 1 week ago
Posts updated: 2 days ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 months ago