Bulb not spreading light

This code is not working when calling “drawlight“. Why?

on collect do
	if uiok>0 then
		ask "Remove?" then
			option "Yes" then
				call "erasebulb"
			end
			option "No" then
				done
			end
		end
	end
end

on datainit do
	blbx = event.px
	blby = event.py
	blbtmr = 4
	blblf = 1
	blbuf = 1
	blbrf = 1
	blbdf = 1
	blblx = blbx
	blbuy = blby
	blbrx = blbx
	blbdy = blby
end

on drawlight do
	log "{blbx},{blby}"
	call "datainit"
	while blbtmr>0 do
		blbtmr = blblf
		blbtmr += blbuf
		blbtmr += blbrf
		blbtmr += blbdf
		if blbtmr==0 then
			uiok = 1
			log "uiok = 1"
			done
		end
		wait 1 then
			if blblf>0 then
				blblx -= 1
				ishole = name blblx,blby
				if ishole=="black" then
					blblf = 0
				else
					dcx = blblx
					dcy = blby
					call "drawlightlr"
				end
			end
			if blbuf>0 then
				blbuy -= 1
				ishole = name blbx,blbuy
				if ishole=="black" then
					blbuf = 0
				else
					dcx = blbx
					dcy = blbuy
					call "drawlightud"
				end
			end
			if blbrf>0 then
				blbrx += 1
				ishole = name blbrx,blby
				if ishole=="black" then
					blbrf = 0
				else
					dcx = blbrx
					dcy = blby
					call "drawlightlr"
				end
			end
			if blbdf>0 then
				blbdy += 1
				ishole = name blbx,blbdy
				if ishole=="black" then
					blbdf = 0
				else
					dcx = blbx
					dcy = blbdy
					call "drawlightud"
				end
			end
		end
	end
end

on drawlightud do
	if ishole=="Linelr" then
		tell dcx,dcy to
			swap "Linex"
		end
	elseif ishole=="Blank" then
		tell dcx,dcy to
			swap "Lineud"
		end
	elseif ishole=="white" then
		tell dcx,dcy to
			swap "Lineud"
		end
	end
end

on drawlightlr do
	if ishole=="Lineud" then
		tell dcx,dcy to
			swap "Linex"
		end
	elseif ishole=="Blank" then
		tell dcx,dcy to
			swap "Lineud"
		end
	elseif ishole=="white" then
		tell dcx,dcy to
			swap "Linelr"
		end
	end
end

on erasebulb do
	swap white
	call "eraselight"
end

on eraselight do
	log "{blbx},{blby}"
	call "datainit"
	while blbtmr>0 do
		blbtmr = blblf
		blbtmr += blbuf
		blbtmr += blbrf
		blbtmr += blbdf
		if blbtmr==0 then
			uiok = 1
			log "uiok = 1"
			done
		end
		wait 1 then
			log "wait"
			if blblf>0 then
				blblx -= 1
				ishole = name blblx,blby
				if ishole=="black" then
					blblf = 0
				else
					dcx = blblx
					dcy = blby
					call "eraselightlr"
				end
			end
			if blbuf>0 then
				blbuy -= 1
				ishole = name blbx,blbuy
				if ishole=="black" then
					blbuf = 0
				else
					dcx = blbx
					dcy = blbuy
					call "eraselightud"
				end
			end
			if blbrf>0 then
				blbrx += 1
				ishole = name blbrx,blby
				if ishole=="black" then
					blbrf = 0
				else
					dcx = blbrx
					dcy = blby
					call "eraselightlr"
				end
			end
			if blbdf>0 then
				blbdy += 1
				ishole = name blbx,blbdy
				if ishole=="black" then
					blbdf = 0
				else
					dcx = blbx
					dcy = blbdy
					call "eraselightud"
				end
			end
		end
	end
end

on eraselightlr do
	if ishole=="Linelr" then
		tell dcx,dcy to
			swap "white"
		end
	elseif ishole=="Linex" then
		tell dcx,dcy to
			swap "Lineud"
		end
	end
end

on eraselightud do
	if ishole=="Lineud" then
		tell dcx,dcy to
			swap "white"
		end
	elseif ishole=="Linex" then
		tell dcx,dcy to
			swap "Linelr"
		end
	end
end

Well, let’s start with what is it supposed to do? and what does it currently do?

Also, I see you have a wait in a while-loop which is normally kinda dangerous as it can lock up the system. If you are looking to make animations, I would make a variable that increases in each draw and you check its value to determine the animation state.

That was meant for emulating akari but I might trapped by that sentence.

This is the working code.

on collect do
	// if uiok>0 then
	ask "Remove?" then
		option "Yes" then
			call "erasebulb"
		end
		option "No" then
			done
		end
	end
	// end
end

on datainit do
	blbx = event.px
	blby = event.py
	// blbtmr = 4
	blblf = 1
	blbuf = 1
	blbrf = 1
	blbdf = 1
	blblx = blbx
	blbuy = blby
	blbrx = blbx
	blbdy = blby
end

on drawlight do
	log "{blbx},{blby}"
	call "datainit"
	// while blbtmr>0 do
	// blbtmr = blblf
	// blbtmr += blbuf
	// blbtmr += blbrf
	// blbtmr += blbdf
	// if blbtmr==0 then
	// uiok = 1
	// log "uiok = 1"
	// done
	// end
	// wait 1 then
	while blblf>0 do
		blblx -= 1
		if blblx<0 then
			blblf = 0
		else
			ishole = name blblx,blby
			if ishole=="black" then
				blblf = 0
			else
				dcx = blblx
				dcy = blby
				call "drawlightlr"
			end
		end
	end
	while blbuf>0 do
		blbuy -= 1
		if blbuy<0 then
			blbuf = 0
		else
			ishole = name blbx,blbuy
			if ishole=="black" then
				blbuf = 0
			else
				dcx = blbx
				dcy = blbuy
				call "drawlightud"
			end
		end
	end
	while blbrf>0 do
		blbrx += 1
		if blbrx>24 then
			blbrf = 0
		else
			ishole = name blbrx,blby
			if ishole=="black" then
				blbrf = 0
			else
				dcx = blbrx
				dcy = blby
				call "drawlightlr"
			end
		end
	end
	while blbdf>0 do
		blbdy += 1
		if blbdy>14 then
			blbdf = 0
		else
			ishole = name blbx,blbdy
			if ishole=="black" then
				blbdf = 0
			else
				dcx = blbx
				dcy = blbdy
				call "drawlightud"
			end
		end
	end
	// end
	// end
end

on drawlightud do
	if ishole=="Linelr" then
		tell dcx,dcy to
			swap "Linex"
		end
	elseif ishole=="Blank" then
		tell dcx,dcy to
			swap "Lineud"
		end
	elseif ishole=="white" then
		tell dcx,dcy to
			swap "Lineud"
		end
	end
end

on drawlightlr do
	if ishole=="Lineud" then
		tell dcx,dcy to
			swap "Linex"
		end
	elseif ishole=="Blank" then
		tell dcx,dcy to
			swap "Lineud"
		end
	elseif ishole=="white" then
		tell dcx,dcy to
			swap "Linelr"
		end
	end
end

on erasebulb do
	call "eraselight"
	swap white
end

on eraselight do
	log "{blbx},{blby}"
	call "datainit"
	// while blbtmr>0 do
	// blbtmr = blblf
	// blbtmr += blbuf
	// blbtmr += blbrf
	// blbtmr += blbdf
	// if blbtmr==0 then
	// uiok = 1
	// log "uiok = 1"
	// done
	// end
	// wait 1 then
	while blblf>0 do
		blblx -= 1
		if blblx<0 then
			blblf = 0
		else
			ishole = name blblx,blby
			if ishole=="black" then
				blblf = 0
			else
				dcx = blblx
				dcy = blby
				call "eraselightlr"
			end
		end
	end
	while blbuf>0 do
		blbuy -= 1
		if blbuy<0 then
			blbuf = 0
		else
			ishole = name blbx,blbuy
			if ishole=="black" then
				blbuf = 0
			else
				dcx = blbx
				dcy = blbuy
				call "eraselightud"
			end
		end
	end
	while blbrf>0 do
		blbrx += 1
		if blbrx>24 then
			blbrf = 0
		else
			ishole = name blbrx,blby
			if ishole=="black" then
				blbrf = 0
			else
				dcx = blbrx
				dcy = blby
				call "eraselightlr"
			end
		end
	end
	while blbdf>0 do
		blbdy += 1
		if blbdy>14 then
			blbdf = 0
		else
			ishole = name blbx,blbdy
			if ishole=="black" then
				blbdf = 0
			else
				dcx = blbx
				dcy = blbdy
				call "eraselightud"
			end
		end
	end
	// end
	// end
end

on eraselightlr do
	if ishole=="Linelr" then
		tell dcx,dcy to
			swap "white"
		end
	elseif ishole=="Linex" then
		tell dcx,dcy to
			swap "Lineud"
		end
	end
end

on eraselightud do
	if ishole=="Lineud" then
		tell dcx,dcy to
			swap "white"
		end
	elseif ishole=="Linex" then
		tell dcx,dcy to
			swap "Linelr"
		end
	end
end