Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Arrays and Removal

I'm modeling a haunted house exploration after the board game Betrayal at House on the Hill.
There's a random stack of tiles. Some tiles (Dusty Hallway) can be used in the basement, or on the ground floor, or on the upper floor. Others (Underground Lake) can only appear on one specific floor.
What I've done so far - which works well for a single floor - is create an array of the tiles possible for each given floor, using the (shuffled:) macro, and then use the (move:) macro to grab the 1st item over and over. This does a nice job of simulating the process of shuffling the tiles and then grabbing the top tile.
The trouble is those multi-floor tiles. When I find that Dusty Hallway on the ground floor I don't want it repeated upstairs.
Is there a way to remove a single item from an array, by name? I know you can use "-" to make an array return a reduced value, and it seems to remove all instances of that value (the example on Harlowe is (a:1,1,2,3,4,5) - (a:1,2) (is (a:3,4,5))) but the thing it returns seems to be a string, not another array.

My sample code for proof-of-concept before I try it with 40+ tiles:
(set: $food to (shuffled: "Apple", "Banana", "Carrot"))
(set: $altfood to (shuffled: "Apple", "Banana", "Carrot", "Daikon", "Elderberry", "Fig"))
(move: $food's 1st into $foodOne)(set: $temp to (a: $foodOne))
(set: $altfood to (array: $altfood - $temp))
(move: $food's 1st into $foodTwo)(set: $temp to (a: $foodTwo))
(set: $altfood to (array: $altfood - $temp))
(move: $food's 1st into $foodThree)(set: $temp to (a: $foodThree))
(set: $altfood to (array: $altfood - $temp))
(move: $altfood's 1st into $foodFour)
(move: $altfood's 1st into $foodFive)
(move: $altfood's 1st into $foodSix)

First is $foodOne, second is $foodTwo, third is $foodThree.
Fourth is $foodFour, fifth is $foodFive, sixth is $foodSix.

Here's the output for that code:
I can't find a '1st' data name in an array►
I can't find a '1st' data name in an array►

First is Apple, second is Banana, third is Carrot.
Fourth is Fig,Carrot,Banana,Elderberry,Daikon, fifth is 0, sixth is 0.

It looks like it's making $altfood into a single-item array with the contents of the entire array in its one slot as a string. That string gets moved into the $foodFour variable and then the other 2 variables get left in the lurch.

Comments

  • The syntax of your (set: $altfood to (array: $altfood - $temp)) is incorrect, it should be:
    (set: $altfood to $altfood - $temp)
    
    ... when testing it is a good idea to print out the value of your variables as you go along so you can see how they are changing:
    {(set: $food to (shuffled: "Apple", "Banana", "Carrot"))
    (set: $altfood to (shuffled: "Apple", "Banana", "Carrot", "Daikon", "Elderberry", "Fig"))
    }''Initialize''
    food: $food
    altfood: $altfood
    
    ''Move 1st from food to foodOne, delete temp from altfood''{
    (move: $food's 1st into $foodOne)(set: $temp to (a: $foodOne))
    (set: $altfood to $altfood - $temp)}
    foodOne: $foodOne
    food: $food
    altfood: $altfood
    
    ''Move 1st from food to foodTwo, delete temp from altfood''{
    (move: $food's 1st into $foodTwo)(set: $temp to (a: $foodTwo))
    (set: $altfood to $altfood - $temp)}
    foodTwo: $foodTwo
    food: $food
    altfood: $altfood
    
    ''Move 1st from food to foodThree, delete temp from altfood''{
    (move: $food's 1st into $foodThree)(set: $temp to (a: $foodThree))
    (set: $altfood to $altfood - $temp)}
    foodThree: $foodThree
    food: $food
    altfood: $altfood
    
    {(move: $altfood's 1st into $foodFour)
    (move: $altfood's 1st into $foodFive)
    (move: $altfood's 1st into $foodSix)
    }foodFour: $foodFour
    foodFive: $foodFive
    foodSix: $foodSix
    altfood: $altfood
    
    First is $foodOne, second is $foodTwo, third is $foodThree.
    Fourth is $foodFour, fifth is $foodFive, sixth is $foodSix.
    
  • FANTASTIC!
    While a syntax error makes me feel like an idiot for a couple seconds, it's deeply gratifying to find out that the working solution is also easier to write than what I had.
Sign In or Register to comment.