How to get choicescript to recognise that a particular option has been chosen more than others and then display it?

Hi there all,

I have another choicescript query which needs resolving so I hope you guys can help.

How can I get choicescript to recognise that a particular option has been chosen more than others and then display it?

Four instance, let’s say that in one of the scenes of a game, you are in a shop. The PC chooses to buy six apples and five oranges. How can I get choicescript to recognise that the PC has chosen to buy more apples than any other item and then display it as such:

“You left the shop with apples being your primary option and with oranges beeing your secondary option.”

I hope what I have tried to explain makes sense and as always, thanks in advance for any help I receive.

Variables and If statements. You can use temporary variables if it’s only important to that small section.

When someone buys something do *set oranges +1

Then compare them with a
*if apples > oranges
*if oranges > apples
*if oranges = apples

Say if I have many more items that the PC can choose from, how do I just do what you said but in detail?

First you ask yourself “is this important? Do I really need the code to know this.”

If you decide you really need to know this, then, start comparing.

If (apples > oranges) AND (apples > peaches) AND (apples > strawberries) with appropriate brackets too. And you do that for everything.

Oh… This is going to be fun. It looks like a lot of coding needs to be done tomorrow then. I’ll try it out and i’ll let you know if I need any more help.

although I haven’t tried it, I see how that would work for setting the pc’s primary choice option but how would you display the pc’s secondary choice option?

Similar.

You can, of course reword things.

What do you want to buy most of?
*choice
#Apples
#Oranges

What is your secondary purchase
*choice
#Apples
#Oranges

There may also be a way to code precisely what you want, simpler than the method I’ve suggested. However, I’d suggest taking this as an opportunity to scour the wiki to find out if there’s an alternative way you can think of doing things. A lot of coding can be problem solving, and trying to work out how to get the code to do what you want.

I showed you the way I’d do it. However, I wouldn’t actually do things your way at all. I’d likely decide, well it doesn’t matter what you bought most of. Or if it does matter, I’d be more likely to change my choice wording like I’ve suggested.

@addicted First thing you want to do is create your variables.

*create apples 0
*create oranges 0
*create primary “”
*create secondary “”

When you are about to buy something.

*choice 
	#Buy Apples 
		*set apples +1
		*gosub prime 
                *goto checkup
	#Buy Oranges
		*set oranges +1
		*gosub prime
                *goto checkup
        #I'm done shopping 
                *gosub prime
                *goto checkup
<pre *if (apples = oranges) Looks like you brought the same amount of apples and oranges... *finish *else You brought more ${primary} than ${secondary}. You should consider buying chocolate in the future.
*label prime
*if (apples > oranges)
	*set primary "apples" 
	*set secondary "oranges"
*if (oranges > apples)
	*set primary "oranges"
	*set primary "apples"
*return 

Something to keep in mind and also mentioned by fairy. The more items you plan on using for the primary, secondary, and the likes you’ll need to use more brackets and use AND/OR commands. That can easily be found on the wiki on the *if command section. Best of luck.