Replace with other randomly

Question: How do I radomly replace a piece from a list using the “Replace with other” trait ?

Unfortunately, this isn’t easy, unless the only difference between the possible replacement pieces can be represented by a single randomly selected trait (in that case, you can use a single piece, and trigger the random trait selection on placement).

Assuming that isn’t the case, you will need:

  1. a separate Replace with other trait for each possible replacement piece.
  2. a Dynamic Property with a command to set it to a random number with the value {Random(x)}, where “x” is the number of possible pieces.
  3. a Trigger Action for each Replace with other, all triggered on the same named command, which checks for the Dynamic Property to be equal to a specific number, and then runs the matching Replace with other.
  4. one more Trigger Action, which calls the Dynamic Property to generate the random number, then calls the other Trigger Actions to trigger the correct Replace with other trait.
  • Replace With
    • Path: …
    • Key: replace1
  • Replace With
    • Path: …
    • Key: replace2
  • …
  • Trigger
    • Key: doReplace
    • Action keys: [replace1],
    • Property: {Replacement == 1}
  • Trigger
    • Key: doReplace
    • Action keys: [replace2]
    • Property: {Replacement == 2}
  • …
  • Dynamic Property
    • Name: Replacement
    • Commands:
      • Key: pickReplacement
      • Expression: {Random(n)} (n is the number of possiblities)
  • Trigger trait
    • Key: replace
    • Command: Random replacement
    • Action keys: [pickReplacement, doReplace]

Just to pin it out a bit more.

Please remember to mark the solution to your question. It helps everybody.

Yours,
Christian

I wouldn’t use replace-with-other. I’d put all the replacements in an always-shuffle deck. In my main piece, I send a GKC to get a random piece from the deck. The replacement would go to the main piece. Then I’d delete the main piece.

Thank you for your reply. I must have done something wrong because it doesn’t seem to work.

Is this the proper sequence of traits as they appear on the screen? Also, in the Dynamic Property the Type should be “Set Value Directly”?

You can try to debug the above by adding context menu commands to f.ex. the Replace with traits - just to see that they execute correctly.

You can also add Report Action traits that reacts to the Trigger and Dynamic Property traits, to see that they are executed as you expect. F.ex.

  • Report trait
    • Keys: pickReplacement
    • Report: {"~Replacement pick is set to " + Replacement}

Note, you must either give a literal integer value for n in Random(n) or define it as a Property -for example

  • Marker
    • Name: n
    • Value: 10 As an example

For these traits, the order is not important. If you have Restrict Acccess or similar traits, in the same piece or prototype, you must consider where such a trait is relative to the above traits.

Yes, that’s correct.

Note that it is imporant that you do not give the conditional Trigger traits any user visible context menu command. That field should be left blank.

Yours,
Christian