Skip to content

Fix game.objective being overwritten by change_grammar() when quests exist - #374

Open
Greg Sochanik (gregyoto) wants to merge 2 commits into
microsoft:mainfrom
gregyoto:fix/objective-overwritten-by-change-grammar
Open

Greg Sochanik (gregyoto) wants to merge 2 commits into
microsoft:mainfrom
gregyoto:fix/objective-overwritten-by-change-grammar

Conversation

@gregyoto

Copy link
Copy Markdown

Summary

What was happening

PR #240 added code in build() to copy a manually-set _objective from a previous build (line 788-789 of maker.py). However, change_grammar() is called after this copy (line 803), and it unconditionally overwrites the objective:

# game.py line 460 (before this fix)
self.objective = describe_event(Event(policy), self, self.grammar)

This means the preserved objective gets clobbered whenever the game has quests with a winning policy (i.e. most games).

The fix

One line change in game.py:

# Only auto-generate if no objective has been set
if self._objective is None:
    self.objective = describe_event(Event(policy), self, self.grammar)

Test plan

  • New test test_manually_defined_objective_with_quests verifies that a manually-set objective survives build() and compile() when the game has quests
  • Existing test test_manually_defined_objective continues to pass (games without quests)
  • Normal games without a custom objective still get auto-generated objective text as before

Made with Cursor

…exist

PR microsoft#240 (fixing microsoft#239) added code to preserve a manually-set objective
across build() calls. However, the preservation happens before
change_grammar() is called, which unconditionally overwrites the
objective via describe_event(). This means the fix only worked for
games without quests (no winning policy = no describe_event call).

The fix: only auto-generate the objective in change_grammar() if one
hasn't already been set (self._objective is None).

Fixes microsoft#373

Co-authored-by: Cursor <cursoragent@cursor.com>
@gregyoto

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@MarcCote

Marc-Alexandre Côté (MarcCote) commented Feb 8, 2026 •

Copy link
Copy Markdown
Contributor

Great catch. Thanks for the PR. You can ignore the PEP8 error, I have fixed it in an upcoming PR (#372).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The guard prevents objectives from regenerating when callers subsequently change grammar.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Prevents manually assigned objectives from being overwritten during GameMaker compilation.

Changes:

  • Guards automatic objective generation.
  • Adds a quest-based regression test.
File Description
textworld/​generator/​game.py Conditionally generates objectives.
textworld/​generator/​tests/​test_maker.py Tests custom objective preservation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +460 to +461
if self._objective is None:
self.objective = describe_event(Event(policy), self, self.grammar)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

game.objective still overwritten by change_grammar() when quests exist (regression of #239)

3 participants