allows you to control one or more pistons
indexing of pistons goes from 0 to (getPistonsCount() - 1)
component name - pistonController
methods:
- pistonController.setLength(index:number, length:number) - sets the length for a this piston
- pistonController.getLength(index:number):number - returns the length set for this piston
- pistonController.setVelocity(index:number, velocity:number) - sets the velocity for a this piston
- pistonController.getVelocity(index:number):number - returns the velocity set for this piston
- pistonController.setForce(index:number, force:number) - sets the force for a this piston (default: 100000)
- pistonController.getForce(index:number):number - returns the force set for this piston (default: 100000)
- pistonController.getPistonsCount():number - returns the number of pistons connected to the controller
- pistonController.isPistonAvailable(index:number):boolean - returns true if there is a piston with this index
- pistonController.getMaxVelocity(index:number):number - returns the maximum speed available for the given piston
- pistonController.getMaxLength(index:number):number - returns the maximum length available for the given piston
- pistonController.getMaxForce(index:number):number - returns the maximum force available for the given piston (256 piston: 10000000, other pistons: 100000)
local pistonController = getComponent("pistonController")
local speed = 3
local height = 4
function onTick(dt)
local tick = getUptime() * speed
for i = 0, pistonController.getPistonsCount() - 1 do
pistonController.setLength(i, ((math.sin(math.rad(tick - (i * 16))) + 1) / 2) * height)
pistonController.setVelocity(i, pistonController.getMaxVelocity(i))
end
end
_enableCallbacks = true
local p1 = getComponentByLabel("pistonController", "1")
local p2 = getComponentByLabel("pistonController", "2")
function onTick(dt)
local state = getTick() % 40 >= 20
p1.setVelocity(0, p1.getMaxVelocity(0))
p2.setVelocity(0, p2.getMaxVelocity(0))
p1.setLength(0, state and 4 or 0)
p2.setLength(0, state and 0 or 4)
end
_enableCallbacks = true