function init()
	motor = FindJoint("motor")	
	min, max = GetJointLimits(motor)
	target = 0
	speed = 0

	startbutton = FindShape("startbutton")
	dropbutton = FindShape("dropbutton")
	stopbutton = FindShape("stopbutton")
	
	SetTag(startbutton, "interact", "loc@START")
	SetTag(dropbutton, "interact", "loc@DROP")
	SetTag(stopbutton, "interact", "loc@EMERGENCY_STOP")
	
	buttonClick = LoadSound("clickup.ogg")
	motorSound = LoadLoop("vehicle/hydraulic-loop.ogg")
	oldMotorPos = GetJointMovement(motor)
	body = FindBody("body")
end


function tick(dt)
	local current = GetJointMovement(motor)
	if GetPlayerInteractShape() == startbutton then
		if InputPressed("interact") then
			target = max
			speed = 1
			PlaySound(buttonClick,GetShapeWorldTransform(startbutton).pos)
		end
	end
	if GetPlayerInteractShape() == dropbutton then
		if InputPressed("interact") then
			target = min
			speed = 10
			PlaySound(buttonClick,GetShapeWorldTransform(dropbutton).pos)
		end
	end
	if GetPlayerInteractShape() == stopbutton then
		if InputPressed("interact") then
			target = current
			speed = 0
			PlaySound(buttonClick,GetShapeWorldTransform(stopbutton).pos)
		end
	end

	if GetJointMovement(motor) - oldMotorPos > 0.01 then
		PlayLoop(motorSound,GetBodyTransform(body).pos)
	end

	oldMotorPos = GetJointMovement(motor)
	SetJointMotorTarget(motor, target, speed)	
end

