Ask coding questions

← Back to all posts
Stormfront's Special AI Thingamajig
UmarQureshi4 (1)

Me again. Quick question - if a player wants to build a section of his/her headquarters, then how can I make it so that I have a list of options that aren't repeated?

I've used a 'choice( )' statement for this, but it keeps showing the same option twice or thrice.

I also want to make it so that on the other options (interact, repair, upgrade [excluding end shift]) that it can list the sections you've already built.

<Umar Qureshi>

Answered by InvisibleOne (3206) [earned 5 cycles]
View Answer
InvisibleOne (3206)

Have all your choices in a list:

list = ['bla bla bla', 'lol', 'another choice']

then when you pick one of those choices using random, remove that choice from the list so it won't be picked again

import random

choice1 = random.choice(list)
choice2 = random.choice(list)
# and so on
UmarQureshi4 (1)

Epic - I'll try this method and see if it can function in my script.

If you are wondering why I keep asking questions, I ain't an experienced programmer - more of a beginner myself.

<Umar Qureshi>


UmarQureshi4 (1)

Uhh, now it's displaying the arrays/lists on the terminal - how do I fix this?

<Umar Qureshi>