How to pass global state between modules effectively?

In my program, I have a main game loop as the foundation, in which the state changes (conditionally) 60 times per second.

In addition to this loop, I have a module that handles keyboard input signals.

I can’t properly implement the use of a single state (state variable) in each module, because if I create a variable in one module and pass it to another, when I modify the variable in that other module, the variable doesn’t change in the original module.

When I made the state variable using fibers or goblins, performance drops and is heavily affected by the device the game runs on. How can I solve my problem?

I’m guessing that you mean that you are trying to use set! on something from another Scheme module (as opposed to a wasm module, an entirely different thing) and it’s not working as you’d expect. If so, then the thing to understand is that when module A exports foo and module B imports module A, the foo variable in module B is not the same variable as in A. So, (set! foo 42) in module B has the effect of mutating the value of the foo variable in module B only. What you want is to modify the object that foo in A and foo and B both point at, and for that you will need a mutable data structure of some kind, like a box.

Atomic Boxes saved my soul

The “atomic” part of atomic boxes is not necessary in your case btw. Atomic boxes are for lock-free concurrency but on Hoot that’s not currently a concern. There isn’t traditional multithreading on the web/wasm so the interface is just there for compatibility with Guile. For a plain old box that doesn’t have any other semantics, see SRFI-111 or just make your own since it’s very simple. You could even have a <game-state> record type with all the mutable state in it.