Simple way to verify which of x number of stats has the highest number

Okay, so I’m relatively proficient at coding, and I’m honestly probably just having a major brainfart due to stress.

I need a way to, hopefully without a subroutine (I abhor using them, because they like to overcomplicate the code and confuse the automated testing), have the program decide which of 4 stats is the highest.

Basically, I’m implementing a personality quiz, of sorts, wherein the maximum possible number of points for any of the four attributes is 11.

Currently, I am using a very primitive:

*if ((sardonic > mean) and (sardonic > sincere)) and (sardonic > jokester)
 *set personality "sardonic"
 words
 *goto whatever
*elseif ((blah blahblah) and (whatever)) and (whatever)
 *set personality "whatever"
 *goto label
*elseif ((something) and (something)) and (darkside)
 *set personality "darkside"
 *goto label
*else
 *set personality "jokester"
 *goto whatever

the issue I’m currently seeing is that, using random answers, I managed to have equal points in “mean” and “jokester”, and the program chose to set the personality as “jokester”, even though, logically, it should have set to “mean”, due to “mean” being the earlier *elseif statement.

I could, theoretically, keep my code the way it is and just rework the math of the attributes within the quiz, I guess, but I’d prefer the code just to work the way I want it to.

Like I said, I’m probably brainfarting and am most likely not explaining this as well as I’d prefer, but :woman_shrugging:

1 Like

I think it is defaulting to the *else command because, as far as I can tell, there is no *elseif for “mean”. At least not in the snippet you pasted here.

1 Like

bleh, okay, the actual code, without my snarkiness is:

*if ((Sardonic > Mean) and (Sardonic > Sincere)) and (Sardonic > Jokester)
 *set personality "sardonic"
 It seems you're known to be rather sardonic and sarcastic. 
 At least, according to this quiz, anyway.
                                                                
 *goto afterquiz2
*elseif ((Mean > Sardonic) and (Mean > Sincere)) and (Mean > Jokester)
 *set personality "mean"
 Apparently, this quiz thinks you're kind of "mean". You're not 
 entirely sure you agree, but oh well.

 *goto afterquiz2
*elseif ((Sincere > Sardonic) and (Sincere > Mean)) and (Sincere > Jokester)
 *set personality "sincere"
 Aw, the quiz thinks you're a sincere person! That's always 
 nice to hear.
                                                                
 *goto afterquiz2
*else
 *set personality "jokester"
 Ah, so even the silly daytime talkshow quiz can appreciate 
 your advanced, [i]tasteful[/i] sense of humor! Maybe you'll 
 become a bigger fan, eh?

 *goto afterquiz2
 *label afterquiz2

I’ve never been one to do specific *else statements after a specific *else, like it’s nested. Can you even do that without breaking the code?

I mean, I don’t mind reworking the math. I kinda already did it so that the final question has slightly more value than the rest, to try to throw off the bad math.

I’d just rather have it work the way it’s supposed to, lol

ETA: if the indentation is wrong, it’s because I’m connected to the internet on one computer and not the other, so it’s been a trip trying to move the code from my coding computer to my crappy laptop that’s somehow managing to connect to the internet.

I don’t know if there is any way in the code you posted to specifically check for values that are accidentally equal to each other, and this is probably why it is going to the *else "jokester – i.e. because there are no conditions defined for these two variables being equal, and so it defaults to the last one because there is nothing in the *elseif’s that satisfies it.

You probably don’t have to completely overhaul the entire checking system, though. It should work if you just alter the possible values to never possibly be equal to each other, like having there be unequal chances to get certain answers on your quiz, therefore making it impossible for the variables to add to a number that would be equal to another variable.

1 Like

Yeah, I had a feeling I’d have to do that. I’m not a fan of giving uneven variable chances, because it makes it seem like one path is the “true” one, but if I don’t want an inordinate amount of “jokester” characters, I’ll probably have to do that. Better than spending 3 hours trying to come up with a system that does what I want it to and makes things far too complex.

1 Like

Here is how I do it for a lot of variables:

*set mainstat "bold"
*set mainstatval bold
*if culture > mainstatval
	*set mainstat "culture"
	*set mainstatval culture
*if intellect > mainstatval
	*set mainstat "intellect"
	*set mainstatval intellect
*if skullduggery > mainstatval
	*set mainstat "skullduggery"
	*set mainstatval skullduggery
*if observe > mainstatval
	*set mainstat "observe"
	*set mainstatval observe
*if persuade > mainstatval
	*set mainstat "persuade"
	*set mainstatval persuade

Note that this method resolves ties in favor of the stats that come earlier in the *if chain, so order the checks accordingly.

3 Likes

Quick overhaul:
Replace

*else
 *set personality "jokester"
 Ah, so even the silly daytime talkshow quiz can appreciate your advanced, [i]tasteful[/i] sense of humor! Maybe you'll become a bigger fan, eh?

 *goto afterquiz2
 *label afterquiz2

with

*elseif (Jokester > Sardonic) and (Jokester > Sincere) and (Jokester > Mean)
 *set personality "jokester"
 Ah, so even the silly daytime talkshow quiz can appreciate your advanced, [i]tasteful[/i] sense of humor! Maybe you'll become a bigger fan, eh?

 *goto afterquiz2
 *label afterquiz2

And then add individual

*else

For… something else.

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