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

Ending a function end the code

Started by Meuleuh, 05 October 2018 - 11:53 AM
Meuleuh #1
Posted 05 October 2018 - 01:53 PM
I'm doing a OS Startup animation, but because a part of it is simply a repeated animating, I'm using a function to call it easier. The thing is that, when I call that function, i don't know why, in the middle of the function, the code end without giving me any error code.

Here the code:

function loadAnimation(state)
posTemp = term.getCursorPos()
term.setCursorPos(26,13)
term.setBackgroundColor(colors.blue)
 
if (state == 0) then
  write("+")
 
end
if (state == 1) then
  write("x")
 
end

term.setCursorPos(posTemp)
term.setBackgroundColor(colors.white)

sleep(1)

end
term.setBackgroundColor(colors.blue)
term.setCursorBlink(false)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(19,5)
textutils.slowPrint("MeuleuhOS v1.0")
write("Initializing OS...")
loadAnimation(0)
term.setCursorPos(10,10)
term.setBackgroundColor(colors.white)
write("|")
term.setCursorPos(positionTemporaire)
sleep(5)
write("||||||||||||||||||||||||||||||||")
term.setBackgroundColor(colors.blue)
term.setCursorPos(15,15)
write("    OS Initialized    ")
sleep(5)

The problem is probably situated around…

function loadAnimation(state)
posTemp = term.getCursorPos()
term.setCursorPos(26,13)
term.setBackgroundColor(colors.blue)
 
if (state == 0) then
  write("+")
 
end
if (state == 1) then
  write("x")
 
end

	    term.setCursorPos(posTemp) --Here
term.setBackgroundColor(colors.white) --or here

sleep(1) --or here because the sleep doesn't occur either

end

Thanks for help and feel free to use my code while trying to debug it (He isn't done because I stopped working on the main part when I wanted to use that function)
Bomb Bloke #2
Posted 05 October 2018 - 02:18 PM
posTemp = term.getCursorPos()
.
.
.
term.setCursorPos(posTemp)

term.getCursorPos() returns two values, but you're only assigning one of these to a variable. You then pass that single value to term.setCursorPos(), which requires two inputs: this is probably where your crash is located.

I admit I'm not sure why you're not seeing an error to that effect, though…
Meuleuh #3
Posted 05 October 2018 - 02:24 PM
posTemp = term.getCursorPos()
.
.
.
term.setCursorPos(posTemp)

term.getCursorPos() returns two values, but you're only assigning one of these to a variable. You then pass that single value to term.setCursorPos(), which requires two inputs: this is probably where your crash is located.

I admit I'm not sure why you're not seeing an error to that effect, though…

Thanks for the advice. I fixed achieved to fix it!