controllables.MicroController
- class controllables.MicroController(port: Optional[int])
Reference to a microcontroller part.
The following example forwards all of the messages it receives on to every microcontroller that is assigned in its ports.
from controllables import MicroController from scriptruntime import Runtime from ports import Port #get a message stream stream = Runtime.message_stream() #get a list of all microcontrollers in my ports microcontrollers = [ MicroController(port) for port in Port.ports() if Port.port_type(port) == MicroController ] while True: #for each message we receive for message in stream: #forward it on to all of our microcontrollers for microcontroller in microcontrollers: microcontroller.message(message)
- static self() controllables.MicroController
Returns the microcontroller to which the calling script is attached.
- message(message: str)
Sends a message which can be read via
message_stream()
on the script attached to this microcontroller.Note
The message is not sent instantly, but will arrive within a few milliseconds.
from controllables import MicroController #sending script mc = MicroController(0) mc.message("hello world")
from scriptruntime import Runtime #recieving script message_stream = Runtime.message_stream() while True: for message in message_stream: print("recieved me message: " + message)
- name() str
Returns the user editable name of the controllable as found in the properties tab of the game.
from ports import PortReference print(PortReference(0).name())