You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm creating a text choose your own adventure game in which there's essentially a machine for story plot and a machine for the character, which is invoked on the root of the former. I'm trying to limit the story machines transitions using guards, based on items the character has, its state, etc. Is it possible to access the child machine's state and context w/i the parent machines guards?
exportconstCharacterMachine=setup({types: {context: {}asCharacterContext,events: {}as{type: "damage"}|{type: "infect"},},}).createMachine({id: "char",initial: "idle",context: {name: "Moss",pronouns: generateAllPronouns('fem'),race: {name: "gnome",adj: "gnomish"},state: "healthy",abilities: {str: {name: "strength",score: 4}},items: []},states: {idle: {on: {"damage": {actions: ()=>assign({state: "injured",})},"infect": {actions: [assign({state: "sick",})]},},},dead: {}},});exportconstStoryMachine=setup({types: {context: {},meta: {}as{story: string},events: {type: "damage"},},actors: {character: CharacterMachine,},}).createMachine({id: "elsewhere",initial: "start",context: {},states: {start: {meta: {story: `You find yourself in a dark forest. You can hear the sound of rustling leaves and distant howls.`,},on: {explore: {target: "explore",description: "Venture forth",},},},explore: {meta: {story: "As you explore deeper into the forest, you come across a mysterious cave. A strange voice calls out: '#name, come closer.'",},on: {prepareForBattle: {target: "prepareForBattle",description: "Enter the cave, drawing your weapon.",guard: ({context})=>{/* Look to see if character has any weapons in CharacterMachine context.items */}},stopToRest: {target: firstLevel.therear,description: "Catch your breath before heading in",guard: ({context})=>{/* Check character machine context.state */}},},}},});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm creating a text choose your own adventure game in which there's essentially a machine for story plot and a machine for the character, which is invoked on the root of the former. I'm trying to limit the story machines transitions using guards, based on items the character has, its state, etc. Is it possible to access the child machine's state and context w/i the parent machines guards?
Beta Was this translation helpful? Give feedback.
All reactions