The above has code that has a line ‘set PlayerHealth = 80.0’ without initializing it. Maybe that’s right but I don’t think so because when I copy and paste this in my vs code, it is showing that there is no variable called PlayerHealth.
I came across this trying to grant the player health with a verse device but having all sorts of issues.
The correct way to set someone’s Health is getting their instigation (agent) and then you retrieve their fort_character like this
if(FortCharacter:=Agent.GetFortCharacter[]): # GetFortCharacter Might fail that's why I have it on an IF and put brackets on it and not just ()
FortCharacter.SetHealth(50.0) # To Set Health
FortCharacter.SetShield(50.0) # To Set Shield
Also those starting lessons are merely to teach the “logic” of the language, even if “PlayerHealth” was saved as a float on the device it wouldn’t really function or change the player’s health. Interactions with the actual players I believe is teached on the later lessons
Ok thank you! I’ve come to understand that a lot of the code there is for demonstration purposes and assumes you would write it in a function or something like that.
I fixed my code with the following function:
# Get the FortCharacter of the agent
if (FC := Agent.GetFortCharacter[]):
loop:
# Get the health of the Fortnite character and make sure it is not full
if(FC.GetHealth() < FC.GetMaxHealth()):
# Store current health plus regen rate variable in a new constant
NewHealth := FC.GetHealth() + HealthRegenRate
# Set the player's health to the new health
FC.SetHealth(NewHealth)
# Wait for the cooldown period
Sleep(Cooldown)```
I appreciate your response. Sorry for the delay. I'm trying to be more active on here.
PS I don't see a way to choose your response as the 'answer'. But I would!