threads_this_03.gm 653 B

123456789101112131415161718192021222324252627282930313233343536
  1. global create_robot = function(x, y, name)
  2. {
  3. return { x = x, y = y, name = name, id, class="robot" };
  4. };
  5. global behaviour_stupid = function()
  6. {
  7. print( .name + " is acting stupidly" );
  8. };
  9. global behaviour_seek = function()
  10. {
  11. print( .name + " is seeking resources" );
  12. };
  13. global behaviour_rest = function()
  14. {
  15. print( .name + " is resting" );
  16. };
  17. global robot_def = {
  18. {"tom", behaviour_seek},
  19. {"mike", behaviour_rest},
  20. {"jane", behaviour_stupid},
  21. {"bob", behaviour_stupid},
  22. {"sarah", behaviour_seek}
  23. };
  24. for(id = 0; id < 5; id = id + 1)
  25. {
  26. robot = create_robot(1 * id, 10 * id, robot_def[id][0]);
  27. robot:thread(robot_def[id][1]);
  28. }
  29. sleep(1);