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

[ERROR] Obscure one

Started by Fashter, 29 October 2012 - 03:30 AM
Fashter #1
Posted 29 October 2012 - 04:30 AM
Hi, guys!

I got a weird error here. The code below is obviously a function and as it is, currently, you'll get an error saying that an eof was expected (too many ends) but, when I remove just 1 end, it gives the error that an end is expected to end the while loop. Keep in mind that I only removed 1 end! Feel free to try this and help me.

Here is the code that i'm trying to call:

function readASCII()
dec = rs.getBundledInput( bDataSide )
if dec == 4 then
  return end
msgp = string.char( dec )
--msg = msg..msgp
print( "Debug: "..msgp) --delete me later
rs.setBundledOutput( bVerifySide,3 )
sleep(0.5)
rs.setBundledOutput( bVerifySide,0 )
while true do
  if rs.getBundledInput == 6 then
   rs.setBundledOutput( bVerifySide,0 )
   return true
  elseif rs.getBundledInput == 25 then
   return false
  end
end
end
end
Bubba #2
Posted 29 October 2012 - 05:09 AM
Can't test it right now as I'm on my phone, but on line 4 you're attempting to return end. I'm pretty sure that it will work if you change that to return true or return false, add an end on the next line, and remove an end from the last line.
Grim Reaper #3
Posted 29 October 2012 - 05:22 AM
Fortunately, Challenge.Accepted, the code on line for executes successfully since LUA is pretty great at ignoring how you format your code :P/>/>

However, on lines 12 and 15 your trying to compare an integer to a function rather than whatever is returned by those function calls (I assume that's what your after?). This is not your problem though.

I removed the final end statement from your code and it was interpreted properly, however I haven't tested it with redstone. Also, with the code provided it doesn't appear that the variables 'bDataSide' and 'bVerifySide' have been defined and therefore they have 'nil' values. I'm fairly sure this is only a section of your program and those variables are declared globally.

My only suggestion is that you remove the very last end statement; it appears there is one too many.
ChunLing #4
Posted 29 October 2012 - 05:24 AM
Are you trying for a structure like this:
function readASCII()
    dec = rs.getBundledInput( bDataSide )
    if dec == 4 then return end
    msgp = string.char( dec )
    --msg = msg..msgp
    print( "Debug: "..msgp) --delete me later
    rs.setBundledOutput( bVerifySide,3 )
    sleep(0.5)
    rs.setBundledOutput( bVerifySide,0 )
    while true do
        if rs.getBundledInput == 6 then
            rs.setBundledOutput( bVerifySide,0 )
            return true
        elseif rs.getBundledInput == 25 then
            return false
        end
    end
end
end -- last end is extra
Or this:
function readASCII()
    dec = rs.getBundledInput( bDataSide )
    if dec == 4 then return -- this "end" is extra
        msgp = string.char( dec )
        --msg = msg..msgp
        print( "Debug: "..msgp) --delete me later
        rs.setBundledOutput( bVerifySide,3 )
        sleep(0.5)
        rs.setBundledOutput( bVerifySide,0 )
        while true do
            if rs.getBundledInput == 6 then
                rs.setBundledOutput( bVerifySide,0 )
                return true
            elseif rs.getBundledInput == 25 then
                return false
            end
        end
    end
end
Fashter #5
Posted 29 October 2012 - 06:00 AM
Fortunately, Challenge.Accepted, the code on line for executes successfully since LUA is pretty great at ignoring how you format your code :P/>/>

However, on lines 12 and 15 your trying to compare an integer to a function rather than whatever is returned by those function calls (I assume that's what your after?). This is not your problem though.

I removed the final end statement from your code and it was interpreted properly, however I haven't tested it with redstone. Also, with the code provided it doesn't appear that the variables 'bDataSide' and 'bVerifySide' have been defined and therefore they have 'nil' values. I'm fairly sure this is only a section of your program and those variables are declared globally.

My only suggestion is that you remove the very last end statement; it appears there is one too many.

CC forums eff'd it up when i tried to paste it so it's a little hard to read :P/>/>. When I remove an end, it tells me i should add one and when i leave it, it tells me i need another if statement. And you'd be correct, it was just part of my program and the 2 variables are defined locally. But to clarify, i have removed the end like this:

function readASCII()
dec = rs.getBundledInput( bDataSide )
if dec == 4 then
  return done
end
msgp = string.char( dec )
--msg = msg..msgp
print( "Debug: "..msgp) --delete me later
rs.setBundledOutput( bVerifySide,3 )
sleep(0.5)
rs.setBundledOutput( bVerifySide,0 )
while true do
  if rs.getBundledInput (bVerifySide ) == 6 then
   rs.setBundledOutput( bVerifySide,0 )
   return true
  elseif rs.getBundledInput( bVerifySide ) == 25 then
   return false
  end
end
end
I did this before I made the post and it still gives me an error on line 66 of my entire program that 'end' expected to close while loop at line 47. My entire program:
Spoiler


local modelNumber = 631626677
local bDataSide = "back"
local bVerifySide = "right"
local failID = 0 --Set me
local mID = 0 --Set me too

function readASCII()
dec = rs.getBundledInput( bDataSide )
if dec == 4 then
return done
end
msgp = string.char( dec )
--msg = msg..msgp
print( "Debug: "..msgp) --delete me later
rs.setBundledOutput( bVerifySide,3 )
sleep(0.5)
rs.setBundledOutput( bVerifySide,0 )
while true do
if rs.getBundledInput (bVerifySide ) == 6 then
rs.setBundledOutput( bVerifySide,0 )
return true
elseif rs.getBundledInput( bVerifySide ) == 25 then
return false
end
end
end

if gbang.rednetOpen() == false then
print( "No modem found. Do you want to continue? Y/N" )
print( "Rednet features will be disabled.n" )
failInput = read()
end
if failInput == "Y" then
elseif failInput == "y" then
elseif failInput == "N" then
print( "Please attach a modem." )
return
elseif failInput == "n" then
print( "Please attach a modem." )
return
end

gbang.clear( 1,1 )
gbang.cPrint( "G&K Industries Standard Issue" )
gbang.cPrint( "Model Number: "..modelNumber )

while true do
os.pullEvent( "redstone" )
if rs.getBundledInput( bVerifySide ) == 1 then
if readASCII() == true then
elseif readASCII() == "end" then
rednet.send( mID,msg )
elseif readASCII() == false then
print( "Failed." )
rednet.send( failID,"Failed"..os.computerID() )
while true do
local ev,id,rnetmsg = os.pullEvent( "rednet_message" )
if id == failID then
if rnetmsg == "LOCATE "..os.computerID() then
rednet.send( failID,gps.locate() )
os.reboot()
end
end
end
end
end
Fashter #6
Posted 29 October 2012 - 06:06 AM
Are you trying for a structure like this:
function readASCII()
	dec = rs.getBundledInput( bDataSide )
	if dec == 4 then return end
	msgp = string.char( dec )
	--msg = msg..msgp
	print( "Debug: "..msgp) --delete me later
	rs.setBundledOutput( bVerifySide,3 )
	sleep(0.5)
	rs.setBundledOutput( bVerifySide,0 )
	while true do
		if rs.getBundledInput == 6 then
			rs.setBundledOutput( bVerifySide,0 )
			return true
		elseif rs.getBundledInput == 25 then
			return false
		end
	end
end
end -- last end is extra
Or this:
function readASCII()
	dec = rs.getBundledInput( bDataSide )
	if dec == 4 then return -- this "end" is extra
		msgp = string.char( dec )
		--msg = msg..msgp
		print( "Debug: "..msgp) --delete me later
		rs.setBundledOutput( bVerifySide,3 )
		sleep(0.5)
		rs.setBundledOutput( bVerifySide,0 )
		while true do
			if rs.getBundledInput == 6 then
				rs.setBundledOutput( bVerifySide,0 )
				return true
			elseif rs.getBundledInput == 25 then
				return false
			end
		end
	end
end
This didn't work. It expected an end to end the if (same error i encountered when i tried this before). Test it first :P/>/>
Heracles421 #7
Posted 29 October 2012 - 06:18 AM
I'm confused, you should have some organization in your code, it really helps when tracking errors. I can't really help you because I'm using my iPod, but I'll reformat your code and I'll find that error later
Luanub #8
Posted 29 October 2012 - 06:27 AM
You need to put ()'s after functions. Your missing them in several locations.

rs.getBundledInput
--should be
rs.getBundledInput()
Fashter #9
Posted 29 October 2012 - 07:35 AM
I'm confused, you should have some organization in your code, it really helps when tracking errors. I can't really help you because I'm using my iPod, but I'll reformat your code and I'll find that error later
I know.
CC forums eff'd it up when i tried to paste it so it's a little hard to read :P/>/>.

In other words, you don't need to.

You need to put ()'s after functions. Your missing them in several locations.

rs.getBundledInput
--should be
rs.getBundledInput()
Grim said this and it's irrelevant to the error at hand.
However, on lines 12 and 15 your trying to compare an integer to a function rather than whatever is returned by those function calls (I assume that's what your after?). This is not your problem though.
I've fixed that, but that wasn't the error I was getting.
Luanub #10
Posted 29 October 2012 - 07:42 AM
An eof(end of file) expected could be caused by the missing ()'s, have you tried fixing it? The code won't run until you do.
ChunLing #11
Posted 29 October 2012 - 11:12 AM
Look, what is the function supposed to do? Which of those "end"s is the one to remove? Without knowing that, there isn't a lot of point, the function may end up working but it won't do what you want.
huettner94 #12
Posted 29 October 2012 - 03:03 PM
The following errors are in your code (I don't know if they cause your problem):

Line 10: you return done, I'm pretty sure that you want to return the String "end", because "done" is never used
Line 13: you probably want to declare msg globally so you can acces it from your main program (and don't comment it out)
Line 62-66: you need 6 times end after os.reboot() if I understand you code right

If it doesn't work could you attatch a screenshot?