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

Turtle choise

Started by lllScorpionlll, 09 March 2013 - 11:20 PM
lllScorpionlll #1
Posted 10 March 2013 - 12:20 AM
Hi all,

I have a problem with my code.
When I start this code and press the key y or n then nothing will happen. Tutle do not print:

print "Na prvu poziciu v inventary turtly"
print "daj torche a uhlie daj lubovolne !"
print "Ked uz to mas pripravene stlac \"y\""

and error is black screen…
Please help me…



function vyber()
while true do
event, p1 = os.pullEvent()
  if event == "char" and p1 == "y" then
   term.clear()
   term.setCursorPos (1,1)
   print "Na prvu poziciu v inventary turtly"
   print "daj torche a uhlie daj lubovolne !"
   print "Ked uz to mas pripravene stlac \"y\""
   if event == "char" and p1 == "y" then
    for l = 2,16 do
	 turtle.select(l)
	 turtle.refuel(64)
	 if turtle.getFuelLevel() == 0 then
	  term.clear()
	  term.setCursorPos (1,1)
	  print "Turtlicka nema palivo! Vloz uhlie do"
	  print "inventara turtlicky !"
	  return
	 end
    end
    begin()
    begin2()
   end
  break
  elseif event == "char" and p1 == "n" then
   term.clear()
   term.setCursorPos (1,1)
   print "Vloz uhlie lubovolne do inventara"
   print "turtlicky !"
   print "Ked uz to mas pripravene stlac \"y\""
   if event == "char" and p1 == "y" then
    for l = 1,16 do
	 turtle.select(l)
	 turtle.refuel(64)
	 if turtle.getFuelLevel() == 0 then
	  term.clear()
	  term.setCursorPos (1,1)
	  print "Turtlicka nema palivo! Vloz uhlie do"
	  print "inventara turtlicky !"
	  return
	 end
    end
    begin()
    begin2()
   end
  end
end
end
vyber()
LordIkol #2
Posted 10 March 2013 - 09:37 AM
Tested the code and for me it works.
Everything is printed then error cause you only posted the function vyber()
I guess the problem is somewhere in the function begin() or begin2()

Greets
Loki
Left #3
Posted 10 March 2013 - 11:47 AM
Ok. Simple error. When you use the print function it needs to have brackets containing what to print. For example.

print("Example")

not

print "Example"
Dlcruz129 #4
Posted 10 March 2013 - 11:49 AM
Ok. Simple error. When you use the print function it needs to have brackets containing what to print. For example.

print("Example")

not

print "Example"

Actually, either will work.
Lyqyd #5
Posted 10 March 2013 - 11:59 AM
Dlcruz is right, but the circumstances under which this works are fairly limited.
Left #6
Posted 10 March 2013 - 12:10 PM
OK. Didnt know that. Instead of using the input "y" use y's key code ( same for n ) and the event returns "key"

y = 21
n = 49

if event == "key" and p1 == 21 then < Like that