HTML Beginner Programing Question

Atlas

Member
Aug 5, 2016
228
371
I know board games, I don't know programing. I am trying to learn twine and other basic concepts.

What I want is to create a randomization system where I metaphorically put things in bags. The bag is the potential pool of outcomes. An outcome is randomly drawn.

Two questions:
  1. If it is a loot bag and a sword is drawn, how do I remove the sword from the bag while leaving the rest to be drawn later?
  2. What do I do if I want to have requirements on what can be drawn? For instance, if a mage draws the sword it auto redraws a new, useful item instead?
How do I begin approaching an answer? I'm thinking of this as what operations I would do in the real world, not how a programmer approaches the same task. I believe I know how I could do this (poorly) with a series of if, then statements if the bags were static. Any help would be appreciated.
 

xj47

Member
Nov 4, 2017
241
409
You can do something like this:

Code:
# Setup data
picker = someCharacter()
itemPool = [item1, item2, item3, ...]

# Create list of items that can potentially be gotten
candidates = []
for item in itemPool:
    if picker.canGet(item):
        candiates.add(item)

# If no items are valid, handle that here
if len(candidates) == 0:
    return

# Pick a random item from the candidates
pickedItem = random.choice(candidates)
# Remove acquired item from pool
itemPool.remove(pickedItem)
For the "pool" you can just use a general list or array structure.
 
  • Like
Reactions: quarzo and Atlas