Choicescript_stat coding percents

I was changing somethings in my choicescript_stat and I wondered if we can put a top on the percent.

My code looks like this:
*stat_chart
*if Intimidating > 100
*set Intimidating 100
percent Intimidating

I know that will give an error. It's just I was wondering if it's possible to do something like that so the status can't go over 100.

Thanks in advance.
2 Likes

edit: see post below re indents. I’d recommend considering using Fairmath for stats, as it is automatically capped at 100.

2 Likes

It’s indented but it appears this error.
QUICKTEST FAILED
Error: choicescript_stats line 31: invalid line; this line should start with ‘percent’, ‘text’, or ‘opposed_pair’
line 30 *stat_chart
line 31 ----*if Intimidating > 100
line 32 --------*set Intimidating 100
line 33 ------------percent Intimidating
I’ll try using Fairmath. Thanks a lot for your quick response! :smile:

Does ChoiceScript allow commands inside a *stat_chart ? I thought all things such as *set or *if had to be run before the charts.

This is what I assumed was required:
*if Intimidating > 100
    *set Intimidating 100

*stat_chart
    percent Intimidating
Can it really be run nested?
*stat_chart
    *if Intimidating > 100
        *set Intimidating 100
    percent Intimidating
2 Likes

@Minnow you’re absolutely right - that’s what I get for posting on my phone :grimacing: I’ll edit the post for correctness!

3 Likes

That’s what I used and it seems to work. Thanks for your help.

3 Likes

One thing you might want to consider, depending on your needs: the way you have this coded, values over 100 will only snap back to 100 when the player actually visits the stats screen. This is fine if all you care about is creating the illusion that you’ve bounded the stat values, but in reality, there’s a very real possibility that the stats will go out-of-bounds and only reset when the player actively goes to check on them.

Unless your game is particularly mechanics-heavy, this probably won’t be a discernible issue for the player—so long as you never try to mix regular arithmetic with fairmath. Then things get really messy, because fairmath categorically does not work on values over 100 or below 0—in fact, I’m reasonably sure you’ll throw an error if you try.

Now, like I said, if you only ever do regular addition and subtraction with your stat values, you can stick with what you’ve got now, and it should work. (Though, your more code-savvy readers might cringe a little if try peeking behind the curtain.) However, if you anticipate even the slightest chance that you’ll ever try to implement fairmath (or want to make your code more efficient in general), I’d recommend saving yourself the headache and making adjustments now.

The obvious solution, of course, is to just exclusively use fairmath, which I believe is what most authors do. But if you don’t want to do this, the other method would be to create a subroutine that snaps out-of-bound values back and *gosub it every time you change a stat value, instead of waiting to correct it until the player visits the stat screen. There’s a tutorial on how to do this here. This is a little more bothersome than other methods, but it’s the most surefire way to mix normal arithmetic and fairmath while avoiding errors.

That all being said: if you decide to commit to exclusively using one method or the other, you can just ignore everything I said and carry on with what you’ve got. Either way, good luck with whatever it is you’re working on!

4 Likes

I was using Fairmath with the skills and not with relationship status.

I will do that, so thanks a lot for the advice.

An easy way to do stat rounding with regular numbers is to just create a big gosub at the end of every scene (or in its own scene) and use *gosub(/*gosub_scene) after every stat check. It might look something like this, which is what I use in my own game:

*label r
*if adr > 100
	*set adr 100
*elseif adr < 0
	*set adr 0
*else
	*comment End

*if oli > 100
	*set oli 100
*elseif oli < 0
	*set oli 0
*else
	*comment End

*if mad > 100
	*set mad 100
*elseif mad < 0
	*set mad 0
*else
	*comment End

...
*return

I then call that gosub after every stat modifcation.

*choice
	#Uh, yeah. I'm giving her a piece of my mind. "I don't remember asking for your input, Madison."
		*set mad -1
		*set oli -1
		*set adr +1 
		*set fire +1
		*gosub r
		"Look, if you're gonna act like that all night, why don't [i]you[/i] leave? I don't even think anyone invited you, considering how awful you are."
		
		"Wow," Madison laughs bitterly. "Real classy."
		
		"Come on, that was unnecessary," Olivia adds. "Just relax, okay? Nobody's here to fight."
2 Likes

Everyone of you are being very helpful. I’ve a lot to considerate with all the advises but this one seems pretty practical for relationship status, at least how I’ve been doing them until now. Thanks a lot!!! :blush:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.