Here is the gist of what I want to do. I have a scene that changes depending on what the highest stat the main character is. However, I don’t know how to do this in the code. I want to emphasize that I ONLY want the player’s HIGHEST stat to affect the scene. I can’t use regular integers (like *if leadership > 50) because the PC may have over 50 in several stats but that isn’t their highest. Thanks in advance. I suspect fairmath or percentages may be the way to go, but I’ve come to a total block.
It’s entirely possible to over-think a particular problem searching for an elegant solution . . . The “brute force” method would work fine here, which in this case would be a simple series of checks using temporary “mainstat” and “mainstatval” variables to carry the name and value of the player’s highest current stat.
Begin by setting these to match the first stat, e.g. Leadership, then iterate through the *if checks, changing these two mainstat values only if another stat is higher, along the following lines.
*label main_stat_calc
*temp mainstat
*set mainstat "Leadership"
*temp mainstatval
*set mainstatval leadership
*if strength > mainstatval
*set mainstat "Strength"
*set mainstatval strength
*if intelligence > mainstatval
*set mainstat "Intelligence"
*set mainstatval intelligence
*if wisdom > mainstatval
*set mainstat "Wisdom"
*set mainstatval wisdom
*if dexterity > mainstatval
*set mainstat "Dexterity"
*set mainstatval dexterity
(etc. for as many stats as needed)
*return
Also, by giving this segment of code its own *label and ending with a *return command, you effectively turn it into a subroutine, meaning that you can run this check again (just by using the *gosub command) anywhere in the same scene file to update the name and value of the player’s current “main stat”, without having to repeat any of the actual code.
In your actual story scripting you would first update the name and value of the player’s current main stat using the *gosub command, then make use of it as required, e.g.
*gosub main_stat_calc
*if mainstat = "Wisdom"
(etc.)
If you’re likely to use this subroutine in more than one scene file, just copy-paste it to the bottom of each file and define “mainstat” and “mainstatval” in mygame.js rather than as *temp variables.
I was working on this halfway and thought I’d just throw in my 2 cents. The logic is pretty much the same with what @Vendetta said above, with addition that you may keep it down to only one temporary “container”. In the event you need to fetch the corresponding value, than two temps would be necessary.
Say we have your stats as attrib1, attrib2 and so on, which are to be replaced with the actual stat names, Strength, Leadership etc. We name the temporary container winstat.
*temp winstat
*set winstat "attrib1"
*if (attrib1-attrib2) < 0
*set winstat "attrib2"
*if (attrib2-attrib3) < 0
*if (attrib1-attrib3) < 0
*set winstat "attrib3"
*if (attrib3-attrib4) < 0
*if (attrib2-attrib4) < 0
*if (attrib1-attrib4) < 0
*set winstat "attrib4"
And later on:
*if winstat="attrib1"
Your storyline for attribute 1 being the highest...
Needs actual testing though, just coming off the top of my head. Hope that helps.
EDIT Two containers might be the way to go because the code wouldn’t add up as you have more stats to check each against the other.
Unfortunately CS doesn’t support arrays, which would be ideal for something like this. While it’s possible to fake an array, it’s highly cumbersome to do so. So I wouldn’t bother to fake it for this purpose. Instead I’d recommend a series of *if statements just as @Vendetta has suggested above. One obscure bit of CS which you may find helpful however is curly paren referencing. So you don’t need a second variable to hold the stat value unless you wish to display it on the screen. Just say for example:
*set highstat "speed"
then you can do things like:
if ({highstat} < stamina)
*set highstat "stamina"
Thank you so much. I had actually managed to somewhat create a solution, but it was buggy and not nearly as elegant as the three of you have presented. Now I know where to start, at least.
Yeah, I would love if Choicescript supported arrays, as it’s the easiest way to find min/max variables, but it would probably make the script too non-coder unfriendly.
So I wrote a little test as I may want to use the same checking for my project…
A few things though.
This doesn’t check if you have two or more stats that are of the same value.
Also the indentation on the if’s could go a little crazy as more stats are added, in which case a different approach may be required. Other than that it works pretty well. If anyone finds a bug feel free and post here.
http://fca.hes78.com/csgame/mygame/scenes/script_stathighest.txt
Thank you SO much. I tried to create my own work-around for the issue that the original script didn’t recognize opposing stats, but I couldn’t get it to recognize one of the variables as a number. What I mean by that is that a variable like “leadership” has a number like 50 or so associated with it depending on the player. I couldn’t get the script to recognize the number associated with the variable.
I’ll be trying out your script and I’ll let you know how it works.
Hello Vendetta,
Are you still active? I was wondering if you might be willing to use your enormous brain on an issue I’m puzzled by:
How do you get Choicescript to recognise the variable with the highest value. . . and then display it in your stats screen?