IlyaSemenov / grammy-scenes

Nested named scenes for grammY
MIT License
26 stars 0 forks source link

Local nested scenes #4

Open IlyaSemenov opened 2 years ago

IlyaSemenov commented 2 years ago

Modularizing parts of logic either leads to one-off global scenes, or excessive use of labels/goto. I'd want to setup nested scenes locally within the context of an outer scene.

Something like:

scene.scene("inner", scene => {
  scene.do(...)
  scene.wait(...)
})

scene.call("./inner") // Not sure how to reference a local scene?
ruxxzebre commented 2 years ago

Hi! I've seen an example of calling nested scene ctx.scene.call("add_item"); How nested scenes are actually implemented here, or how to bring the nested scene into a global one? Would be grateful for clarification!

IlyaSemenov commented 2 years ago

@ruxxzebre nesting may mean two things:

1) nested declarations 2) nested invocations

This issue mentions the need of nested declarations. Nested invocations (of globally declared scenes) are already working. You may think of that as nested calls of global functions (calling one global function in middle of another global function).

In the example that you refer to, the code implies that add_item is an another (global) scene:

const addItemScene = new Scene("add_item")

addItemScene.do().... // configure it

sceneManager.scene(addItemScene) // register it in the global scene manager

// ...

// from another scene:

ctx.scene.call("add_item")

Hope that makes sense now.