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

Sorry. Another Un-explained Error

Started by kaioo1312, 28 October 2013 - 07:48 AM
kaioo1312 #1
Posted 28 October 2013 - 08:48 AM
Sorry for the third topic today.

I went through my 'defcon' code and it says defcon : 209 attempt to index ? (a function value). I have looked everywhere for this error and how to solve it (i even looked in the lua manual) and i couldn't find this error code anywhere. The line that was in the error was 'rednet.close(n)' this had the function to determine n above it.

Pastebin:

http://pastebin.com/
theoriginalbit #2
Posted 28 October 2013 - 09:12 AM
I'd say that at some point, you've named on of your functions `rednet` and since you don't use local variables you're polluting the environment with a bunch of old variables and functions.

NOTE: After your program has finished anything that isn't localised remains! as such you should always localise your variables when you don't need them to be able to be accessed externally (i.e. an API).

I point you back to this: http://www.computerc...post__p__150830

@Hellkid98
Spoiler
You can even do this

print"Hello World"
Please stop telling people about this stupid syntax that Lua has… Or at least make sure that they know how stupid it is!

How stupid it really is
It only works with strings and only when you're passing a single argument. As such I don't think this syntax should ever be "advertised" especially to newbies!
Edited on 28 October 2013 - 08:19 AM
TheOddByte #3
Posted 28 October 2013 - 09:15 AM
I'm not sure, But I just looked at the top of your code and saw that you set the cursorpos to a new line everytime.

write("Hello World")
write("!")

--[[
Output:
Hello World!
--]]

print("Hello World")
print("!")

--[[
Output:
Hello World
!
--]]
Write keeps writing the text on the same line while print prints on another line each time ;)/>



And you don't need parantheses around every string
I kinda meant this part

if input == ( "Hello World!" ) then
	print("Hello World!")
end

Can be

if input == "Hello World!" then
	print("Hello World!")
end

You can even do this

print"Hello World"
Even though I suggest you use parantheses when printing/writing
It only works with strings and only when you're passing a single argument as mentioned by TheOriginalBIT above.




And I saw when you are trying to call the function 'passwordInput' in the function 'usernameInput' you are trying call it before it's declared.

Undeclared

hello() -- Undeclared so you can't call it

local function hello()
	print("Hello World!")
end

Declared

local function hello()
	print("Hello World!")
end

hello() -- Now you can call it since it's declared above

- Hellkid98

EDIT: Thanks for pointing that out TOBIT :)/>
kaioo1312 #4
Posted 28 October 2013 - 09:43 AM
i havent named a function 'rednet'
theoriginalbit #5
Posted 28 October 2013 - 09:49 AM
i havent named a function 'rednet'
You could have at some point in time, test the script again, but this time make sure to disable startup files and reboot the computer before running the script.

Basically what the attempt to index ? (a x value) means is that you've attempted to access a table, or use an API, when it is actually a different value (specified by x in the brackets).

For example this would say a number value

local foo = 5
print(foo.bar)
This would say a boolean value

local foo = true
print(foo.bar)
and this would work fine

local foo = {["bar"] = "hello"}
print(foo.bar)
kaioo1312 #6
Posted 28 October 2013 - 10:28 AM
I have renamed some functions and rebooted and it works :D/>
p.s the pastebin code will be deleted as this is a secret :ph34r:/>
theoriginalbit #7
Posted 28 October 2013 - 10:34 AM
I have renamed some functions and deleted the line the error was on then it came up again so i added it back. This is still not working :unsure:/>
You could have at some point in time, test the script again, but this time make sure to disable startup files and reboot the computer before running the script.