~starkingdoms/starkingdoms

ref: cd7053cdc98554b3e38dba6927a0e00d411b49ad starkingdoms/kabel_test/test/runtime/turbo_oop.kab -rw-r--r-- 708 bytes
cd7053cd — ghostly_zsh codegen and also functioning strings 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// modules.select(type, group ...)
//
// select all super thrusters that are in both the 'forward' and 
// 'lowpoweronly' user-defined groups
//
// 'forward' and 'lowpoweronly' are vecs of modules that have 
// been tagged in the ship editor as such

function sleep(h) {}

var lp_forwards = modules.select(modules.types.SuperThruster, "forward", "lowpoweronly");
var sensors = modules.select(modules.types.ShipProximitySensor);

loop { 
  // yes, i think we need 'loop' - while True 
  // may confuse beginners

  sleep(1); // 1 second
  
  // if something is less than 15u away,
  if (sensors.read() < 15) { 
    lp_forwards.activate();
  } else {
    lp_forwards.off(); // alias of Module.deactivate
  }
}