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

program skipping entire peices of itself

Started by cmurtheepic, 23 November 2012 - 06:24 AM
cmurtheepic #1
Posted 23 November 2012 - 07:24 AM
i wrote a program that i am going to use to add a user to my network. i wrote it on a advanced computer cause i like advanced computers. but it would get to a line and just stop the program their when their clearly was a continuous line of coding after it. i put a function their and it went on. even sometimes parts of the write"" and print "" would not display properly and it sometimes would even load a peice of code like this:

-- it would go
write "-> "
x = io.read()
--then
write "would you like to register"
-- so it would show up like this

->
what would you like to register
--but it was supposed to run like this
write "would you like to register"
write "->"
x = io.read()
please help me figure what is going on here!
here is the full code
:

--this is going to identify any new login databases that join the network
function recieve()
	  event, param1 = os.pullEvent()
	  if event == "key" and param1 == "[" then
			  id, message = rednet.recieve()
	  end
end
-- this is going to send the login info to the database server
function server()
  term.clear()
  term.setCursorPos(8,1)
  write "sending your login info to server!"
	  o = "New Login info"
	  id = register
	  ld =    --put database id here
	  while true do
	  rednet.send(ld .. o .. "username: ".. h .. "password: ".. i)
	  
end
--this is the registration procedure
function register()
term.clear()
write "what side is your modem on?"
term.setCursorPos(1,3)
write "->"
d = io.read()
write "thankyou"
rednet.open(d)
term.setCursorPos(1,2)
write "####################################"
term.setCursorPos(1,3)
write "#								  #"
term.setCursorPos(1,4)
write "#								  #"
term.setCursorPos(1,5)
write "#								  #"
term.setCursorPos(1,6)
write "#    would you like to register?   #"
term.setCursorPos(1,7)
write "#								  #"
term.setCursorPos(1,8)
write "#		  yes?    no?			 #"
term.setCursorPos(1,9)
write "#								  #"
term.setCursorPos(1,10)
write "####################################"
term.setCursorPos(7,12)
write "type here ->"
term.setCursorPos(20,12)
x = io.read()
if x == "yes" then
write "ok"
sleep(1)
function regi()
term.clear()
term.setCursorPos(1,1)
write "what should your username be?"
term.setCursorPos(1,2)
write "nothing inappropiate"
term.setCursorPos(1,4)
write "->"
term.setCursorPos(4,4)
h = io.read()
term.setCursorPos(1,6)
print ("ok ["..h.."] will be your username")
sleep(2)
term.clear()
term.setCursorPos(1,1)
write "what should your passward be?"
term.setCursorPos(1,2)
write "again nothing innapropiate"
term.setCursorPos(1,4)
write "->"
term.setCursorPos(4,4)
i = io.read()
term.setCursorPos(1,6)
print ("ok ["..i.."] will be your passward")
term.clear()
term.setCursorPos(1,1)
write "ok. this is your info"
term.setCursorPos(1,3)
term.setTextColor(colors.red)
write ("UserName ->"..h)
term.setCursorPos(1,5)
term.setTextColor(colors.blue)
write ("PassWord ->"..i)
term.setCursorPos(7,7)
term.setTextColor(colors.white)
write "continue:   Yes?   No?"
term.setCursorPos(24,9)
write "->"
term.setCursorPos(26,9)
k = io.read()
if k == "yes"then
write "ok"
sleep(1)
server()
end
   elseif k == "no" then
   write "would you like to try again?"
   g = io.read
   if g == "yes" then
   write "ok"
   sleep (1)
   regi()
    elseif g == "no" then
    write "ok"
    sleep(1)
    term.clear()
    term.setCursorPos(1,1)
	  elseif x == "no" then 
	  write "ok"
	  sleep(2)
	  term.clear()
	  term.setCursorPos(1,1)
	  end
    end
   end
end
parallel.waitForAny( recieve())
Grim Reaper #2
Posted 23 November 2012 - 07:33 AM
Could you provide the original code for us to analyze to give you a more accurate explanation of where and why your problem is occurring?
Dlcruz129 #3
Posted 23 November 2012 - 08:22 AM
i wrote a program that i am going to use to add a user to my network. i wrote it on a advanced computer cause i like advanced computers. but it would get to a line and just stop the program their when their clearly was a continuous line of coding after it. i put a function their and it went on. even sometimes parts of the write"" and print "" would not display properly and it sometimes would even load a peice of code like this:

-- it would go
write "-> "
x = io.read()
--then
write "would you like to register"
-- so it would show up like this

->
what would you like to register
--but it was supposed to run like this
write "would you like to register"
write "->"
x = io.read()
please help me figure what is going on here!


write("Would you like to register? ")
write("->")
x = read()
remiX #4
Posted 23 November 2012 - 11:55 AM
I'm super confused with what you're trying to do. But I would have posted what dlcruz129 said. What exactly do you want?
Lyqyd #5
Posted 23 November 2012 - 12:19 PM
Post the full code, not a simplified example.
Orwell #6
Posted 23 November 2012 - 12:58 PM
On the last line, you have:

parallel.waitForAny( recieve())

You don't really need parallel for that (but you probably temporary removed the other function for debugging), but you can't put the parentheses in there (I just gave the explanation for this in another thread of you were you've done the same thing, so look there for an explanation ;)/>/>). It should be this:

parallel.waitForAny( recieve )
cmurtheepic #7
Posted 24 November 2012 - 10:45 AM
ok like i just wrote a new program that allows me to count the resources i dig up with my quarry's

here it is;

--this announces that the variable w is equal to the width of the screen. and the variable h is equal to the height of the screen
local w,h = term.getSize()
local resourcecounterid
local material
-- this allows me to use a command to print a text centered
local function printCentered(str, ypos)
   term.setCursorPos(w/2 - #str/2, ypos)
   term.write(str)
end
--this allows me to combine the command [term.setCursorPos(,)], with[print ""]
local function printAjustablePos(str, ypos, xpos)
   term.setCursorPos(xpos,ypos)
   term.write(str)
end
--this allows me to print textutils centered
local function textutilsCentered(str, nRate, ypos)
  term.setCursorPos(w/2 - #str/2, ypos)
  textutils.SlowWrite(str, nRate)
end

--this gets the resource counter's computercraft id.
printCentered("what is the computercraft id of the resource counter? you can find it by typing in the console [id] and you will get the computercraft id of that computer", 4)
printCentered("-> ", 6)
resourcecounterid = io.read()
write "thank you"
sleep(1)
term.clear()
term.setCursorPos(1,1)
printCentered("what is the material/ore for the turtle to detect?", 4)
printCentered("->", 6)
material = io.read()
printCentered("don't forget to put a compareable of that ore/material on slot 16 of the turtle", 8)
printCentered("or the program/turtle won't work!", 9)
sleep(3)
term.clear()
sleep(.5)
textutilsCentered("counting resources", 7, 3)
--this is the loop that the turtle compares materials in
function detect()
  while true do
	turtle.select(16)
	turtle.compareTo(1)
	if turtle.compareTo(1) == true then
		rednet.send(resourcecounterid, ""..material)
  turtle.drop(all)
		elseif turtle.compareto(1) == false then
	 turtle.drop(all)
	 end
end
end
when it starts it completely ignores the very first line. or :

printCentered("what is the computercraft id of the resource counter? you can find it by typing in the console [id] and you will get the computercraft id of that computer", 4)
it just goes straight to the line :

printCentered("-> ", 6)
please help me figure this out.
remiX #8
Posted 24 November 2012 - 10:51 AM

printCentered("what is the computercraft id of the resource counter? you can find it by typing in the console [id] and you will get the computercraft id of that computer", 4)
The text is way too long to center!
cmurtheepic #9
Posted 24 November 2012 - 10:56 AM
ok i have made changes.
i changed :

local function textutilsCentered(str, nRate, ypos)
  term.setCursorPos(w/2 - #str/2, ypos)
  textuils.SlowWrite(str, nRate)
to

local function textutilsCentered(str, rate, ypos)
  term.setCursorPos(w/2 - #str/2, ypos)
  textuils.slowWrite(str, rate)
and i added a local at the top

local rate

oh ok

ill divide it into lines
remiX #10
Posted 24 November 2012 - 11:02 AM
Here; I fixed it for you and changed the lines a bit…

--this announces that the variable w is equal to the width of the screen. and the variable h is equal to the height of the screen
local w,h = term.getSize()
local resourcecounterid
local material
-- this allows me to use a command to print a text centered
local function printCentered(str, ypos)
   term.setCursorPos((w - #str)/2, ypos)
   term.write(str)
end
--this allows me to combine the command [term.setCursorPos(,)], with[print ""]
local function printAjustablePos(str, ypos, xpos)
    term.setCursorPos(xpos,ypos)
    term.write(str)
end
--this allows me to print textutils centered
local function textutilsCentered(str, nRate, ypos)
    term.setCursorPos((w - #str)/2, ypos)
    textutils.slowWrite(str, nRate)
end

--this gets the resource counter's computercraft id.
term.clear() term.setCursorPos(1,1)
printCentered("Enter ID of resource computer", 2)
repeat
    term.setCursorPos(1,4) term.clearLine()
    printCentered("-> ", 4)
    resourcecounterid = tonumber(read())
until type(resourcecounterid) == "number"
printCentered("Thank you.", 6)
sleep(1)
term.clear()
term.setCursorPos(1,1)
printCentered("what is the material/ore", 4)
printCentered("for the turtle to detect?", 5)
printCentered("-> ", 7)
material = read()
printCentered("don't forget to put a compareable of that", 9)
printCentered("ore/material on slot 16 of the turtle", 10)
printCentered("or the program/turtle won't work!", 11)
sleep(3)
term.clear()
sleep(.5)
textutilsCentered("counting resources", 7, 3)
--this is the loop that the turtle compares materials in
function detect()
    while true do
        turtle.select(16)
        turtle.compareTo(1)
        if turtle.compareTo(1) then
            rednet.send(resourcecounterid, ""..material)
            turtle.drop(all)
        elseif not turtle.compareTo(1) then
            turtle.drop(all)
        end
    end
end

detect()

-- Clean up
term.clear()
term.setCursorPos(1,1)
cmurtheepic #11
Posted 24 November 2012 - 11:14 AM
i need help on getting it to wait for an item to go into slot one then to compare slot 16 to slot 1?
cmurtheepic #12
Posted 24 November 2012 - 11:17 AM
i am getting an error on both remiX's version and My version wich are identicle basically but the error is : rednet:347: positive number expected
help?
remiX #13
Posted 24 November 2012 - 11:21 AM
i am getting an error on both remiX's version and My version wich are identicle basically but the error is : rednet:347: positive number expected
help?

I tested it and it worked fine for me. What did you enter as the ID?
You probably changed
resourcecounterid = tonumber(read())
back to
resourcecounterid = read()
cmurtheepic #14
Posted 24 November 2012 - 12:03 PM
14 and i didnt change anything