states_04.gm 559 B

123456789101112131415161718192021222324252627282930
  1. global state_advance = function()
  2. {
  3. print("Leaving cover and advancing");
  4. };
  5. global state_decide_action = function()
  6. {
  7. print("I have to decide on a next action");
  8. };
  9. global state_hiding = function()
  10. {
  11. print("Behind cover, waiting to advance");
  12. sig = block("advance");
  13. if (sig == "advance")
  14. {
  15. stateSet( awake );
  16. }
  17. };
  18. global init_state = function()
  19. {
  20. stateSet( state_hiding );
  21. };
  22. tid = thread( init_state );
  23. sleep(1);
  24. // Signal isn't thrown, tell this thread to change state
  25. print("Cover explodes!");
  26. stateSetOnThread( tid, state_decide_action );