function init(self)
	self.timeDelta = self.Smarts
end

function main(self)
	self:AnimationStep()
	local claw = GetClaw()

	if self.State == 0 then
		self.BumpFlags.Generic = true
		self.Flags.AlwaysActive = true
		self:SetImage("CUSTOM_PEG")
		self:SetFrame(12)
		if not self.timeDelta then
			self.timeDelta = 0
		end
		if self.XMin ~= 0 or self.XMax ~= 0 or self.YMin ~= 0 or self.YMax ~= 0 then
			self.State = 11 -- with defined area
		else
			self.State = 1 -- without defined area
		end
	end

	-- without defined area:
	if self.State == 1 then
		self.time = GetTime() + self.timeDelta
		self.State = 2
	end
	if self.State == 2 and GetTime() > self.time then
		self:SetAnimation("GAME_BACKWARD50")
		PlaySound("CUSTOM_PEGSLIDE")
		self.State = 21
	end

	-- with defined area (showing up after the player stays for some predefined amount of time in some predefined area):
	if self.State == 11 and claw:InMinMax(self) then
		self.time = GetTime() + self.timeDelta
		self.State = 12
	end

	if self.State == 12 and GetTime() > self.time then
		self:SetAnimation("GAME_BACKWARD50")
		PlaySound("CUSTOM_PEGSLIDE")
		self.State = 21
	end

	-- the peg shows up:
	if self.State == 21 and self.I == 1 then
		self.BumpFlags.Generic = false
		self.BumpFlags.Platform = true
		self:SetFrame(1)
		self.HitRect = {-24,-8,24,32}
		self.State = 22
	end

	-- good practice:
	if self.State == 22 then
		self.State = 23
	end
	if self.State == 23 then
		self.State = 22
	end
end