chat:120: attempt to index ? (a nil value)
My Code:
file = fs.open("ProgramData/Chat/Username", "w")
file:write(newusername) -- This is line 120
file:close()
chat:120: attempt to index ? (a nil value)
file = fs.open("ProgramData/Chat/Username", "w")
file:write(newusername) -- This is line 120
file:close()
Still have same error.Use file.write :3
No, it does not. I thought writing would automatically create the directories, doesn't it?Does the directory exist?
I created the path and it STILL has the same error!Seems it doesn't xD atleast it worked for me once I created it
*Sigh..hmm strange, it fixed the error for me XD
Tried that earlier, got the same exact error.Try using io.open instead of fs.open.
/
|
+ - Folder1
...|
...+- Program
...+- ProgramData
....+- Chat
......+- Username
Okay, the slash in front of ProgramData fixed 1 problem, now when i start the program it says:Also, when using file paths in ComputerCraft programs, the path is not relative to where the program is being run, everything is based off the root directory.
So, for example I had a directory tree like this:/ | + - Folder1 ...| ...+- Program ...+- ProgramData ....+- Chat ......+- Username
If I ran my program in Folder1 and it tried to open "ProgramData/Chat/Username", it wouldn't open "Folder1/ProgramData/Chat/Username", it would open "/ProgramData/Chat/Username"
chat:150: attempt to call nil
-- BETA CONFIG
username = "Default"
WirelessModemSide = "left" -- Define the side
-- your wireless modem is on
-- Available Sides: top, bottom, left, right,
-- front, back
-- END OF BETA CONFIG
line1 = " "
line2 = " "
line3 = " "
line4 = " "
line5 = " "
line6 = " "
line7 = " "
line8 = " "
line9 = " "
line10 = " "
line11 = " "
line12 = " "
line13 = " "
line14 = " "
line15 = " "
line16 = " "
line17 = " "
rednet.open(WirelessModemSide)
function receiver()
id, message = rednet.receive()
term.clear()
term.setCursorPos(1, 1)
line1 = line2
line2 = line3
line3 = line4
line4 = line5
line5 = line6
line6 = line7
line7 = line8
line8 = line9
line9 = line10
line10 = line11
line11 = line12
line12 = line13
line13 = line14
line14 = line15
line15 = line16
line16 = line17
line17 = message
print(line1)
print(line2)
print(line3)
print(line4)
print(line5)
print(line6)
print(line7)
print(line8)
print(line9)
print(line10)
print(line11)
print(line12)
print(line13)
print(line14)
print(line15)
print(line16)
print(line17)
end
function chat()
term.setCursorPos(1, 18)
write("> ")
chatmessageraw = read()
chatmessage = (username..": "..chatmessageraw)
rednet.broadcast(chatmessage)
line1 = line2
line2 = line3
line3 = line4
line4 = line5
line5 = line6
line6 = line7
line7 = line8
line8 = line9
line9 = line10
line10 = line11
line11 = line12
line12 = line13
line13 = line14
line14 = line15
line15 = line16
line16 = line17
line17 = chatmessage
print(line1)
print(line2)
print(line3)
print(line4)
print(line5)
print(line6)
print(line7)
print(line8)
print(line9)
print(line10)
print(line11)
print(line12)
print(line13)
print(line14)
print(line15)
print(line16)
print(line17)
end
term.clear()
term.setCursorPos(1, 1)
if fs.exists("ProgramData/Chat") == false then
print("-------------------------------------------------")
print("| Choose Username |")
print("-------------------------------------------------")
print("| |")
print("| |")
print("| |")
print("-------------------------------------------------")
term.setCursorPos(3, 5)
write("Username: ")
newusername = read()
term.clear()
term.setCursorPos(1, 2)
print("Writing..")
sleep(0.5)
fs.makeDir("ProgramData")
fs.makeDir("ProgramData/Chat")
file = fs.open("/ProgramData/Chat/Username", "w")
file:write(newusername)
file:close()
term.clear()
term.setCursorPos(1, 1)
end
file = fs.open("/ProgramData/Chat/Username", "r")
file = username
file:close() -- Line 150
while true do
parallel.waitForAny(receiver, chat)
end
file = username
username = file:readAll()
Ah, yes. One last thing, the username has some random name.. like "table: 73424782"On line 149, replacefile = username
withusername = file:readAll()
file:close()
--should actually be
file.close()
--and
file:readAll()
--should be
file.readAll()
The reason you are getting this error "chat:150: attempt to call nil" is your using the fs API but using :'s when using the functions. fs uses .'s and io uses :'s.
the command h:close() does not exist for the fs AP so it says your trying to call nil. the syntax for fs is h.close()file:close() --should actually be file.close() --and file:readAll() --should be file.readAll()
local indentation = {}
function indentation.example()
local correct = true
if correct then
for counter = 1, 10 do
print('This is an example of "correct" indentation.')
end
end
end
indentation.example()
Both ways work, that is currently not my problem atm. Look above. EDIT: Last Page
Also, please learn to indent your code with atleast 2 spaces (4 spaces or 1 tab is more common) per block, otherwise people can't read large scripts you make and you might get lost in your own code (and get laughed at by less understanding programmers).
Example of indentation:local indentation = {} function indentation.example() local correct = true if correct then for counter = 1, 10 do print('This is an example of "correct" indentation.') end end end indentation.example()
Hitting the tab key isn't that hard nor is it time consuming.Both ways work, that is currently not my problem atm. Look above. EDIT: Last Page
EDIT: Ninja'dAlso, please learn to indent your code with atleast 2 spaces (4 spaces or 1 tab is more common) per block, otherwise people can't read large scripts you make and you might get lost in your own code (and get laughed at by less understanding programmers).
Example of indentation:local indentation = {} function indentation.example() local correct = true if correct then for counter = 1, 10 do print('This is an example of "correct" indentation.') end end end indentation.example()
I know, my code looks horrible, but the reason I don't is cause I think it's wasting time.
You cannot tab on CC computers, and half my code was done on one.Hitting the tab key isn't that hard.
sType = type(newusername)
print(sType)
Do the same thing for username.You cannot tab on CC computers, and half my code was done on one.Hitting the tab key isn't that hard.
But CC is now able to pull from your clip-board, you should not be doing anything but quick edits in-game with edit. All your work should be done outside in your editor/IDE of choice and transfered over (or edited directly if the files are local).You cannot tab on CC computers, and half my code was done on one.Hitting the tab key isn't that hard.
I'm probably gonna get flamed for this, but, I'm never updating to 1.3 or anything above, I'm sick of the horrible updates. So there is no way I'll get that feature.You cannot tab on CC computers, and half my code was done on one.Hitting the tab key isn't that hard.
If you are playing any version under 1.4 (such as the version that is included on Tekkit), the text editor does not tab. Any version above and when you hit tab the line is indented by 2 spaces.
Hey, thanks. io.open worked! Time to move on and get more annoying errors!Try using io.open() and the just file:read() and see what that does. Since your storing a single word string in the file it should properly read it.
Other things to check:
What do the contents of the file look like after the write?
You can also do something like this to check what the variable type is:Do the same thing for username.sType = type(newusername) print(sType)
Also print them on the screen when they are being written or read so that you can see what it is doing. That should give you an idea as to what is going wrong.
But CC is now able to pull from your clip-board, you should not be doing anything but quick edits in-game with edit. All your work should be done outside in your editor/IDE of choice and transfered over (or edited directly if the files are local).You cannot tab on CC computers, and half my code was done on one.Hitting the tab key isn't that hard.
No, I like updates not to come, unless they're good. They also cause to have modders to update their mods, and stuff like that.I bet you're one of those kind of people who complain if updates don't happen and also if they do.
I'm curious, what makes 1.3.2 a horrible update?
Are the clouds gonna be mad at you now? J:1.3 was a necessary rewrite to allow the modding API. Well worth it in the long run. I'm from alpha too - but I like the changes - I guess that's where we differ - but I'm off topic - bad Cloudy!