
function process_event(e)
{
  if (e==null) return;

  local t=typeof e

  if (e!="update") print("Script event: "+t+" <"+e+">\n")

  if (t=="function") e()
  else if (t=="string")
  {
    if (e=="toggle_monsters")
    {
      monster_spawn_enabled=!monster_spawn_enabled
      if (!monster_spawn_enabled) remove_all_monsters()
    }
    else if (e=="toggle_universe_devmode")
      universe_devmode=!universe_devmode
  }

  foreach (l in listeners) l._processEvent(e)
  // print("processed script event: "+t+" <"+e+">\n")
}


update_check_delay<-0.0


function update_script(dt)
{
  update_check_delay-=dt
  if (update_check_delay<=0)
  {
    update_check_delay=0.5
    destroy_listeners()
    process_event("update")
    destroy_listeners()
    // check_conditions()
  }
}
