82 posts
Posted 05 February 2013 - 09:09 AM
I'm trying to make a chat program, and right now, I'm making the clientside version. Due to that, the rest of the specifics aren't needed. There is an error on line 22 that I can't figure out, I thought it might be that I used the variable cName in a way that it shouldn't, but I changed it. The error is "expected string" on line 22.
-- test
if firstStart == true then
setClientName()
else
-- to be chat client
function setClientName()
write"Insert client name: "
name = read()
print("Thank you"..name.."!")
name = clientName
hWrite = fs.open(cName, "w")
hWrite.write(clientName)
hWrite.close()
firstStart = false
end
if fs.exists(cName) then
local hRead = assert(fs.open(cname, "r"))
cName = hRead.readLine()
hRead.close()
print("Hello "..clientName.."!")
end
end
871 posts
Posted 05 February 2013 - 09:20 AM
name=clientName
hWrite=fs.open(cName,"w")
Just guessing, as you don't give us complete code and we have no idea which is line #22. You seem to be using a lot of different variables to hold the same value for some reason; I'd recommend cleaning that up, and consistently using just one.
82 posts
Posted 05 February 2013 - 09:23 AM
Okay- I edited the code some, but now, it does nothing when I run the program. (Also- that is the current complete code.)
-- test
if firstStart == true then
setClientName()
else
-- to be chat client
function setClientName()
write"Insert client name: "
name = read()
print("Thank you"..name.."!")
name=clientName
hWrite = fs.open("Clientname", "w")
hWrite.write(clientName)
hWrite.close()
firstStart = false
end
if fs.exists("Clientname") then
local hRead = assert(fs.open("clientname", "r"))
cName = hRead.readLine()
hRead.close()
print("Hello "..clientName.."!")
end
end
871 posts
Posted 05 February 2013 - 09:25 AM
:sigh:
I didn't post a fix.
I posted two lines where you assign a variable, and then use a completely different variable. What is cName, and where is it defined? it's nowhere in this code.
Post the full code, on pastebin where we can get line numbers, not just the part you think is relevant.
2217 posts
Location
3232235883
Posted 05 February 2013 - 09:26 AM
-snip-
82 posts
Posted 05 February 2013 - 10:17 AM
As I said- this is the entire code.
http://pastebin.com/vb0pXymM
2217 posts
Location
3232235883
Posted 05 February 2013 - 10:29 AM
line 12: name=clientName
clientName hasnt been defined
line 21: local hRead = assert(fs.open("clientname", "r"))
your using assert, why?
82 posts
Posted 05 February 2013 - 10:35 AM
line 12: name=clientName
clientName hasnt been defined
line 21: local hRead = assert(fs.open("clientname", "r"))
your using assert, why?
Honestly, I'm not sure anymore. It seemed like a good idea at the time.
2088 posts
Location
South Africa
Posted 05 February 2013 - 10:56 PM
Okay- I edited the code some, but now, it does nothing when I run the program. (Also- that is the current complete code.)
-- test
if firstStart == true then
setClientName()
else
-- to be chat client
function setClientName()
write"Insert client name: "
name = read()
print("Thank you"..name.."!")
name=clientName
hWrite = fs.open("Clientname"u;, "w")
hWrite.write(clientName)
hWrite.close()
firstStart = false
end
if fs.exists("Clientname") then
local hRead = assert(fs.open("clientname", "r"))
cName = hRead.readLine()
hRead.close()
print("Hello "..clientName.."!")
end
end
Where do you set firstStart? It should error as you initialize the program because it's nil.If you're trying to make the varuable clientName equal name then change it around:clientName = name
82 posts
Posted 06 February 2013 - 03:06 AM
Thanks to those who helped- I got it working, or, I got the first part of the client working.