This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MayContainVennom's profile picture

Function Causing Errors.

Started by MayContainVennom, 29 July 2013 - 04:54 PM
MayContainVennom #1
Posted 29 July 2013 - 06:54 PM
Hey Guys.

Having another problem with my script. I am encouting the error when you loop too many functions together. This has happend in every code within the project I have sorted them all out but this one. If you can help me with this I would appricate it a lot. The main problem is that I need to work how it work how it does now simply because two of the functions serve as a checking to see if the Peripheral is pulling the right information. (Chat Box)


Code:
Spoilercb = peripheral.wrap("top")

function main()
a, b, c = os.pullEvent("chat")
if b == "MayContainVennom" or b == "Omnibare" or b == "DuckDastardly" or b == "reeceurnot" then
stepTwo()
else
main()
end
end

function stepTwo()
if string.find(c,"!add") ~= nil then
cb.say("What do you want adding "..b.."?")
stepThree()
else
main()
end
end

function stepThree()
d, e, f = os.pullEvent("chat")
l = fs.open("disk/Tasks", "a")
if e == b then
l.writeLine("- "..f)
l.close()
main()
else
stepThree()
end
end

main()
MayContainVennom #2
Posted 29 July 2013 - 10:01 PM
If you're designing your logic in such a way that you need to call a function from within itself, you've designed it wrong.

function main()
	while true do
		a, b, c = os.pullEvent("chat")
		if b == "MayContainVennom" or b == "Omnibare" or b == "DuckDastardly" or b == "reeceurnot" then
			stepTwo()
		end
	end
end

That's your 'main' function re-written without the need to call main from within main. That should give you enough of an idea on how to change the rest of your functions to suit.

Edit: formating is wonky; indentations don't need to be so aggressive.

Okay thanks a lot.