FFL语法问题:where子句第二个标识符choice未被解析识别
This is a quirk of the Anura FFL parser's handling of multi-variable where clauses—specifically, it seems to have a scope resolution limitation when you declare multiple variables in a single where statement. Let's break this down:
What's Happening
In your original code, you declared both player and choice in the same where clause:
) where player=game.players[creature.summoner], choice=creature.choices[0]
The parser only recognizes the first variable (player) in this context, so when your inner if(choice < size(player.deck)) tries to reference choice, it throws the "unknown identifier" error.
The Fix (Proven to Work)
As you discovered, splitting the multi-variable declaration into separate where clauses resolves the issue. This works because each where clause adds its variable to the parser's context sequentially, making all prior variables available to subsequent expressions. Here's your adjusted code:
def(class creature creature, class game_state game) ->commands [ if(creature.choices, if(choice < size(player.deck), [ set(player.deck, player.deck[0:choice] + player.deck[choice+1:]), game.crypt.spawn_cards(creature.summoner, [card]), set(creature.effects_tracking['Buried Treasure'], card), ] where card=player.deck[choice] ) where player=game.players[creature.summoner] where choice=creature.choices[0] ), ]
Why This Works
Anura's FFL parser processes where clauses one at a time, not as a single block of variable declarations. Each new where extends the current scope with its variable, so by splitting player and choice into their own clauses, you ensure choice is properly added to the context before the inner if tries to use it.
Alternative (Less Reliable) Test
If you wanted to experiment, you could try swapping the order of variables in the single where clause to see if choice is recognized first—but given that splitting works reliably, it's the safer and more maintainable approach for your code.
内容的提问来源于stack exchange,提问作者Patrick Parker

