function init()
	motors = FindJoints("motor")
	hingemotors = FindJoints("hingemotor")
	
	dir = 0
	speed = 0.65
	accelerationTime = 2

	startbutton = FindShape("startbutton")
	armbutton = FindShape("armbutton")
	stopbutton = FindShape("stopbutton")
	
	SetTag(startbutton, "interact", "Òöãôö")
	SetTag(armbutton, "interact", "Âîï. òóòôº")
	SetTag(stopbutton, "interact", "Àåãôìíñºí õöòó")	
	
	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
			SetValue("dir", 1, "linear", accelerationTime)
			PlaySound(buttonClick,GetShapeWorldTransform(startbutton).pos)
		end
	end
	if GetPlayerInteractShape() == armbutton then
		if InputPressed("interact") then
			for i=1,#hingemotors do 
				SetTag(hingemotors[i],"hingemotor",1)
			end
			PlaySound(buttonClick,GetShapeWorldTransform(armbutton).pos)
		end
	end
	if GetPlayerInteractShape() == stopbutton then
		if InputPressed("interact") then
			dir = 0
			for i=1,#hingemotors do 
				SetTag(hingemotors[i],"hingemotor",0)
			end
			PlaySound(buttonClick,GetShapeWorldTransform(stopbutton).pos)
		end
	end

	if dir ~= 0 then
		PlayLoop(motorSound,GetBodyTransform(body).pos)
	end

	oldMotorPos = GetJointMovement(motor)

	for i=1,#motors do
		tagValue = 1
		if GetTagValue(motors[i], "motor") ~= "" then
			tagValue = GetTagValue(motors[i],"motor")
		end
		
		SetJointMotor(motors[i], dir*speed*tagValue)
	end
end

