To try out Netwire, I'm implementing Pong using the library. In the code I have a ball wire and a computer paddle wire, and since they depend on each other for some values I've been running into issues with infinite loops. Some pseudo-code to explain:
ball :: Wire () IO GameInput Ball
ball = (... define ball ...) . pcPaddle
pcPaddle :: Wire () IO GameInput Paddle
pcPaddle = (... define pcPaddle ...) . ball
The thing to notice is they take each other for inputs. I've tried to alleviate this by doing the following:
ball :: Wire () IO GameInput Ball
ball = ( ... ) . delay ( ... base paddle init ...) . pcPaddle
and other variations of using the delay
function in these two wires, but I'm getting the <<loop>>
runtime error regardless.
How do I initialize one of the wires so that this system can work?
Of course 5 minutes later I find the magic combination that seems to work. What I did was I altered the inputs the wires took in to be
then when it came to creating my network of wires I did this:
This acknowlegdes their dependency, and gives the paddle the dummy initial value for the ball on it's first pass.