Issues with getting stat_chart to work

Hi! I’ve found out about CoG 4 days ago and decided to try it out without any coding experience whatsoever. While testing the *stat_chart command I’ve run in to some issues I haven’t been able to figure out.

So a quick overview of what is happening in game:
At the start of the game you get to choose your race, each of which has their own default stat attributes. After choosing your race, you get to choose your class; either a warrior, an archer or a mage. This choice affects your stats. So in the example I’m trying to test, I choose to be a Western Human, which has 100 health by default and I choose the warrior class giving me +10 health and a total of 110 health.

This is the code I’ve used for that:
in startup.txt:

*create percentHealth 100
*create currentHealth 100
*create maxHealth 100

in prologue.txt

*fake_choice
	#Western Human
		*set currentHealth 100
		*set maxHealth 100
		*set percentHealth (round(currentHealth/maxHealth)*100)
And you are a..?
*fake_choice
	#Warrior
		*set class 1
		*set currentHealth +10
		*set maxHealth +10
		*set strength +5
		*set iron_sword "unlocked"
		*set potion_of_health +1

in choicescript_stats.txt

Stats:
*stat_chart
	percent percentHealth Health

When testing this in game, there is a part where one of the choices makes you lose 90 points of health. I’ve written this as follows in the scene:
*set currentHealth -90

Now when I check the stats after losing those 90 points of health, it still shows the bar at 100%. I’ve tried numerous things to fix this but all I can manage to do is either have the bar go to 0% completely after losing 90 out of 110 health, or have it at 1% permanently.

Can anyone guide me in the right direction to fix this, because I have run out of ideas.

Thanks in advance!

Sylvio

Your stat_chart shows percentHealth, and you change currentHealth. This is why it doesn’t change. Changing one doesn’t automatically update the other.

But percentHealth is stated as being (round(currentHealth/maxHealth)*100), so shouldn’t it use the latest value set to currentHealth to calculate percentHealth, to then show the value percentHealth has calculated in the stats? Or am I mistaken?

No, it just sets the value as what those variables were at the moment you ran the calculation. It doesn’t store the formula, just the result.

And the calculations don’t run everytime I open the stats page?

Not unless you run the calculation at the stats page.

…okay, that probably sounds confusing. You could do your *set percentHealth piece at the stats page, is what I mean.

That is very confusing to me, ngl

What I mean is, if you want your calculation to run every time you open the stats page, you’ll need to put your *set percentHealth (round(currentHealth/maxHealth)*100) piece in the choicescript_stats.txt.

Okay I tried that, but it still shows my health to be at 0% after losing 90 out of 110 health. Do I also have to adjust anything in the stat_chart command or can I leave that as is when I put *set percentHealth (round(currentHealth/maxHealth)*100) above the stat_chart command in choicescript_stats.txt?

I admit I don’t know… I’ve never tried to do that.

(I would run the calculation where I change the currentHealth, personally.)

1 Like

Well I do really appreciate your help tho. It does kind of make sense that if the stats page calculates everytime I open it, I should run the calculation there every time. So I learned something at least :slight_smile:

I’m not sure about the timing/placement of the code, but I don’t think your formula is formatted correctly. Someone can correct me if I’m wrong, but this might work better. No promises.

*set percentHealth round((currentHealth/maxHealth)*100)

Again, I’m not sure if that’ll help, but I think the syntax you have now may be a little screwy.

1 Like

Your edit seemed to make sense and looked promising, but alas, still shows as 0%.

EDIT:
Oh my lord you two are my heroes. IT FINALLY WORKS! Thank you!!!

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.