Trouble coding gosub for multiple personality traits

Hi everyone, I’m having some trouble coding a gosub to represent multiple personality traits. I need the game to recognize which personality trait the player most uses so I can code flavor text accurately using my *if dom_trait = “personality trait”

I’ve been playing with it for hours and finally got it working…kind of. My test shows that the gosub quits reporting accurate changes about halfway through.

My code looks like this: I know it’s complicated bc I’m testing 12 personality traits plus a neutral ‘mixed’ trait.

*if dom_personality = "true"
	*if ((adaptable > aggressive) and (adaptable > benevolent)) and ((adaptable > charming) and (adaptable > cruel))
		*if ((adaptable > deceptive) and (adaptable > diplomatic)) and ((adaptable > emotional) and (adaptable > honest))
			*if ((adaptable > reserved) and (adaptable > stoic)) and (adaptable > stubborn)
				*set dom_trait "adaptable"
				*return
		*return
	*elseif ((aggressive > adaptable) and (aggressive > benevolent)) and ((aggressive > charming) and (aggressive > cruel))
		*if ((aggressive > deceptive) and (aggressive > diplomatic)) and ((aggressive > emotional) and (aggressive > honest)) 
			*if ((aggressive > reserved) and (aggressive > stoic)) and (aggressive > stubborn)
				*set dom_trait "aggressive"
				*return
		*return
	*elseif ((benevolent > adaptable) and (benevolent > aggressive)) and ((benevolent > charming) and (benevolent > cruel))
		*if ((benevolent > deceptive) and (benevolent > diplomatic)) and ((benevolent > emotional) and (benevolent > honest)) 
			*if ((benevolent > reserved) and (benevolent > stoic)) and (benevolent > stubborn)
				*set dom_trait "benevolent"
				*return
		*return
	*elseif ((charming > adaptable) and (charming > aggressive)) and ((charming > benevolent) and (charming > cruel))
		*if ((charming > deceptive) and (charming > diplomatic)) and ((charming > emotional) and (charming > honest)) 
			*if ((charming > reserved) and (charming > stoic)) and (charming > stubborn)
				*set dom_trait "charming"
				*return
		*return
	*elseif ((cruel > adaptable) and (cruel > aggressive)) and ((cruel > benevolent) and (cruel > charming))
		*if ((cruel > deceptive) and (cruel > diplomatic)) and ((cruel > emotional) and (cruel > honest)) 
			*if ((cruel > reserved) and (cruel > stoic)) and (cruel > stubborn)
				*set dom_trait "cruel"
				*return
		*return
	*elseif ((deceptive > adaptable) and (deceptive > aggressive)) and ((deceptive > benevolent) and (deceptive > charming))
		*if ((deceptive > cruel) and (deceptive > diplomatic)) and ((deceptive > emotional) and (deceptive > honest)) 
			*if ((deceptive > reserved) and (deceptive > stoic)) and (deceptive > stubborn)
				*set dom_trait "deceptive"
				*return
		*return
	*elseif ((diplomatic > adaptable) and (diplomatic > aggressive)) and ((diplomatic > benevolent) and (diplomatic > charming))
		*if ((diplomatic > cruel) and (diplomatic > deceptive)) and ((diplomatic > emotional) and (diplomatic > honest)) 
			*if ((diplomatic > reserved) and (diplomatic > stoic)) and (diplomatic > stubborn)
				*set dom_trait "diplomatic"
				*return
		*return
	*elseif ((emotional > adaptable) and (emotional > aggressive)) and ((emotional > benevolent) and (emotional > charming))
		*if ((emotional > cruel) and (emotional > deceptive)) and ((emotional > diplomatic) and (emotional > honest)) 
			*if ((emotional > reserved) and (emotional > stoic)) and (emotional > stubborn)
				*set dom_trait "emotional"
				*return
		*return
	*elseif ((honest > adaptable) and (honest > aggressive)) and ((honest > benevolent) and (honest > charming))
		*if ((honest > cruel) and (honest > deceptive)) and ((honest > diplomatic) and (honest > emotional)) 
			*if ((honest > reserved) and (honest > stoic)) and (honest > stubborn)
				*set dom_trait "honest"
				*return
		*return
	*elseif ((reserved > adaptable) and (reserved > aggressive)) and ((reserved > benevolent) and (reserved > charming))
		*if ((reserved > cruel) and (reserved > deceptive)) and ((reserved > diplomatic) and (reserved > emotional)) 
			*if ((reserved > honest) and (reserved > stoic)) and (reserved > stubborn)
				*set dom_trait "reserved"
				*return
		*return
	*elseif ((stoic > adaptable) and (stoic > aggressive)) and ((stoic > benevolent) and (stoic > charming))
		*if ((stoic > cruel) and (stoic > deceptive)) and ((stoic > diplomatic) and (stoic > emotional)) 
			*if ((stoic > honest) and (stoic > reserved)) and (stoic > stubborn)
				*set dom_trait "stoic"
				*return
		*return
	*elseif ((stubborn > adaptable) and (stubborn > aggressive)) and ((stubborn > benevolent) and (stubborn > charming))
		*if ((stubborn > cruel) and (stubborn > deceptive)) and ((stubborn > diplomatic) and (stubborn > emotional)) 
			*if ((stubborn > honest) and (stubborn > reserved)) and (stubborn > stoic)
				*set dom_trait "stubborn"
				*return
		*return
	*else
		*set dom_trait "mixed"
		*return

And this is the text it spits out from my tester scene which follows the formula: Your dominant personality is now ${dom_trait}

Your dominant personality is mixed

Your dominant personality is now adaptable

Your dominant personality is now aggressive

Your dominant personality is now benevolent

Your dominant personality is now charming

Your dominant personality is now cruel

Your dominant personality is now cruel

Your dominant personality is now cruel

Your dominant personality is now cruel

Your dominant personality is now cruel

Your dominant personality is now cruel

Your dominant personality is now cruel

Your dominant personality is now cruel

So the gosub gives up after the cruel personality trait test. I’ve tried testing it from the deceptive trait and it does show in the text as ‘Your dominant personality is now deceptive’ but then shows all the other test lines as deceptive too instead of the other traits.

My stats screen registers the change in trait amounts so I know the game is going through the code on the testing page but doesn’t return from the gosub with accurate info.

I’m baffled at this so if anyone has any ideas I’d appreciate it!

1 Like

Okay! I think I figured some parts of it out.
It was an issue with my returns, I think. I put in multiple returns to try and work around the ‘falling into an else command is illegal’ error.

I’ve switched a few of the traits over to a percentage and keeping the rest as numerals.
Still had the same problem after the diplomatic until I just set it all from emotional on under an additional *if dom_personality = “true” and got rid of extra returns.

*if dom_personality = "true"
	*if ((aggressive > benevolent) and (aggressive > charming)) and ((aggressive > cruel) and (aggressive > diplomatic))
		*if ((aggressive > emotional) and (aggressive > reserved)) and (aggressive > stoic)
			*set dom_trait "aggressive"
		*return
	*elseif ((benevolent > aggressive) and (benevolent > charming)) and ((benevolent > cruel) and (benevolent > diplomatic))
		*if ((benevolent > emotional) and (benevolent > reserved)) and (benevolent > stoic)
			*set dom_trait "benevolent"
		*return
	*elseif ((charming > aggressive) and (charming > benevolent)) and ((charming > cruel) and (charming > diplomatic))
		*if ((charming > emotional) and (charming > reserved)) and (charming > stoic)
			*set dom_trait "charming"
		*return
	*elseif ((cruel > aggressive) and (cruel > benevolent)) and ((cruel > charming) and (cruel > diplomatic))
		*if ((cruel > emotional) and (cruel > reserved)) and (cruel > stoic)
			*set dom_trait "cruel"
		*return
	*elseif ((diplomatic > aggressive) and (diplomatic > benevolent)) and ((diplomatic > charming) and (diplomatic > cruel))
		*if ((diplomatic > emotional) and (diplomatic > reserved)) and (diplomatic > stoic)
			*set dom_trait "diplomatic"
			*return
*if dom_personality = "true"
	*if ((emotional > aggressive) and (emotional > benevolent)) and ((emotional > charming) and (emotional > cruel))
		*if ((emotional > diplomatic) and (emotional > reserved)) and (emotional > stoic)
			*set dom_trait "emotional"
			*return
	*if ((reserved > aggressive) and (reserved > benevolent)) and ((reserved > charming) and (reserved > cruel))
		*if ((reserved > diplomatic) and (reserved > emotional)) and (reserved > stoic)
			*set dom_trait "reserved"
			*return
	*if ((stoic > aggressive) and (stoic > benevolent)) and ((stoic > charming) and (stoic > cruel))
		*if ((stoic > diplomatic) and (stoic > emotional)) and (stoic > reserved)
			*set dom_trait "stoic"
		*return
	*else
		*set dom_trait "mixed"
		*return

Now I have two problems. The first is that under the second *if dom_personality = “true” my *elseif statements fall into the illegal error when they don’t in the first *if dom_personality bit. I’ve switched them to just *if statements and that seems to be just fine but I still wonder why they work in the first half but not the second?

Second problem is that, when more than one trait has the same amount the dominant trait should show as ‘mixed’.

Instead, it doesn’t seem to be reading that last *else and instead displays what the last dom_trait was.

*set reserved +7
*gosub_scene traits
Your dominant personality is now ${dom_trait}

*set stoic +8
*gosub_scene traits
Your dominant personality is now ${dom_trait}
	
*set reserved +1
*gosub_scene traits
Dom personality should be mixed: ${dom_trait}

Text:
Your dominant personality is now reserved

Your dominant personality is now stoic

Dom personality should be mixed: stoic

When I make both reserved and stoic the same amount it just displays the last trait it registered as the dom_trait instead of ‘mixed’. :thinking:

If this is all just terrible coding faux pas then whoops.

edit: okay, yeah, it’s definitely something weird with the if else, else, can’t fall into, etc. I’m not sure exactly what’s causing it, but i was able to replicate, even retyping from scratch

Here’s a subroutine that should work fine. It’s a lot of lines but not much code, and if it does break it should be easier to troubleshoot than all the nested *if statements

*label findtrait
*temp tvalue 0
*temp tname "unknown"
*temp mixedflag 0
*if dom_personality = "true"
    *if (tvalue = adaptable)
        *set mixedflag 1
    *if (tvalue < adaptable)
        *set tvalue adaptable
        *set tname "adaptable"
        *set mixedflag 0
    *if (tvalue = aggressive)
        *set mixedflag 1
    *if (tvalue < aggressive)
        *set tvalue aggressive
        *set tname "aggressive"
        *set mixedflag 0
    *if (tvalue = benevolent)
        *set mixedflag 1
    *if (tvalue < benevolent)
        *set tvalue benevolent
        *set tname "benevolent"
        *set mixedflag 0
    *if (tvalue = charming)
        *set mixedflag 1
    *if (tvalue < charming)
        *set tvalue charming
        *set tname "charming"
        *set mixedflag 0
    *if (tvalue = cruel)
        *set mixedflag 1
    *if (tvalue < cruel)
        *set tvalue cruel
        *set tname "cruel"
        *set mixedflag 0
    *if (tvalue = deceptive)
        *set mixedflag 1
    *if (tvalue < deceptive)
        *set tvalue deceptive
        *set tname "deceptive"
        *set mixedflag 0
    *if (tvalue = diplomatic)
        *set mixedflag 1
    *if (tvalue < diplomatic)
        *set tvalue diplomatic
        *set tname "diplomatic"
        *set mixedflag 0    
    *if (tvalue = emotional)
        *set mixedflag 1
    *if (tvalue < emotional)
        *set tvalue emotional
        *set tname "emotional"
        *set mixedflag 0
    *if (tvalue = honest)
        *set mixedflag 1
    *if (tvalue < honest)
        *set tvalue honest
        *set tname "honest"
        *set mixedflag 0
    *if (tvalue = reserved)
        *set mixedflag 1
    *if (tvalue < reserved)
        *set tvalue reserved
        *set tname "reserved"
        *set mixedflag 0
    *if (tvalue = stoic)
        *set mixedflag 1
    *if (tvalue < stoic)
        *set tvalue stoic
        *set tname "stoic"
        *set mixedflag 0
    *if (tvalue = stubborn)
        *set mixedflag 1
    *if (tvalue < stubborn)
        *set tvalue stubborn
        *set tname "stubborn"
        *set mixedflag 0    
    *if (mixedflag = 1)
        *set dom_trait "mixed"
        *set dom_value tvalue
        *return
    *set dom_trait tname
    *set dom_value tvalue
    *return
1 Like

Oh! That works wonderfully!! Thank you so much that solves all the problems I was getting with all my *if statements.

It looks like it’s working great with the different traits and registers the mixed trait just fine! :heart:

I’ll keep testing it and integrate it in my scenes but everything looks like it’s running smoothly, this is awesome, I’ve been puzzling over this all day, you’re a lifesaver.

1 Like

I think you can streamline your code and use less if statements. Check this out:

*label max_trait
*temp trait_1 "adaptable"
*temp trait_2 "aggressive"
*temp trait_3 "benevolent"
*temp trait_4 "charming"
*temp trait_5 "cruel"
*temp trait_6 "deceptive"
*temp trait_7 "diplomatic"
*temp trait_8 "emotional"
*temp trait_9 "honest"
*temp trait_10 "reserved"
*temp trait_11 "stoic"
*temp trait_12 "stubborn"

*temp trait_number 12
*temp dom_trait trait[1]
*temp tie false
*temp counter 2

*label max_trait_foreach
*if ({dom_trait} < {trait[{counter}]})
	*set dom_trait trait[{counter}]
	*set tie false
	*goto max_trait_foreach_continue
*elseif ({dom_trait} = {trait[{counter}]})
	*set tie true
	*goto max_trait_foreach_continue
*label max_trait_foreach_continue
*set counter +1
*if (counter <= trait_number)
	*goto max_trait_foreach
*if (tie)
	*set dom_trait "mixed"
	*return
*return


I’m too late. :joy:

EDIT:
If dom_trait is a global variable in your code change the line: *temp dom_trait trait[1] to *set dom_trait trait[1]. All the rest keep the same.

2 Likes

Lol no problem I appreciate anything anyone says and I’ll study both these codes to try and tackle these kinds of things on my own in the future. Thanks!!

2 Likes

ooh, that’s clean. very pretty :slight_smile:

1 Like

You can also toggle off that error by using implicit control flow:

2 Likes

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