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

Server and other computers (Roaming Profiles)

Started by TimeStop, 29 November 2012 - 05:52 PM
TimeStop #1
Posted 29 November 2012 - 06:52 PM
I am creating a system where multiple computers can connect to a server in computercraft. I am using someone else code (Not from the original wiki) I keep getting this error however:

bios:206: [string "Server"]:21: '=' expected

Server Code:



local users = { "user1" = "password1", "user2" = "password2" }
local senders = { 4, 5 }

local function clear()
		term.clear()
		term.setCursorPos(1, 1)
end

local function connect()
		for _,s in ipairs(rs.getSides()) do
				if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
						rednet.open(s)
						return true
				end
		end
		return false
end

local function isValid(sender)
		for _,id in ipairs(senders) do
				if id == sender then
						return true
				end
		end
		return false
end

if not connect() then
		print("No modem found")
		return
end

clear()
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")

while true do
		local id, msg = rednet.receive()
		if isValid(id) then
				local usr = textutils.unserialize(msg)
				if usr then
						if users[usr.username] == usr.password then
								rednet.send(id, "PASS_OK")
						else
								rednet.send(id, "PASS_WRONG")
						end
				end
		end
end


P.S. I COPIED DIRECTLY FROM COMPUTERCRAFT SO IT WONT LET ME PUT IT IN A CODE SPOILER THING
Edited by
Doyle3694 #2
Posted 29 November 2012 - 07:25 PM
just mark everything and press those <>. it will make code tags around the code
TimeStop #3
Posted 29 November 2012 - 07:31 PM
I tried to but then it adds a bunch of other stuff because of the different colors of the font which added in a bunch of other stuff making the code unreadable so I left it like that. Sorry about the it. Anyway got any ideas about the code?
KaoS #4
Posted 29 November 2012 - 09:54 PM
Well I took a look and there doesn't seem to be anything in your code that should cause that error, I realise that I then shouldn't bother posting, just thought I'd mention that you can use the 'paste as plain text' button to remove all formatting (like those colours) from text, it is the 10th icon in the IPS icons file here
Luanub #5
Posted 29 November 2012 - 10:13 PM
I get a different error when I run the code.

bios:338: [string "test":1: '}' expected

So I changed

local users = { "user1" = "password1", "user2" = "password2" }
--to
local users = { user1 = "password1", user2 = "password2" }
And it works fine.
ChunLing #6
Posted 30 November 2012 - 09:32 AM
ugh. "if isValid(id) then" should be "if senders[id] then", and you can just delete that isValid function. Like luanub spotted, the users table needs to be changed.

The error you reported doesn't make any sense. Use edit in CC to check that exact line number in the program or use the pastebin program if you can.
Doyle3694 #7
Posted 30 November 2012 - 11:18 AM
Chun, dont be so bitter. If you dont want to help him, ignore this thread or if you think something doesn't makes sense, ask nice :)/> Being bitter from the start is not good.
Tiin57 #8
Posted 30 November 2012 - 11:27 AM
Chun, dont be so bitter. If you dont want to help him, ignore this thread or if you think something doesn't makes sense, ask nice :)/> Being bitter from the start is not good.
He's perfectly within his right to be exasperated when someone doesn't even report an error properly.
ChunLing #9
Posted 30 November 2012 - 11:56 AM
No, I'm being bitter about that stupid isValid function. It left a bad taste. Very embittering.

And it's not that I think that TS is reporting the error wrong, but it just doesn't add up, and there are some ways to clear up that inconsistency. I suggested a couple of the easier ones. If I were really mad I would have suggested one of the hard (and painful, and potentially even dangerous) ones.
TimeStop #10
Posted 30 November 2012 - 07:16 PM
I still have the same problem so Im going to try re pasting the code into the computercraft computers. However it is on a server that I host. How can I open the computer so I can repaste my code. I heard that there is a program to open that specific type of program.

Any ideas?
Lyqyd #11
Posted 30 November 2012 - 08:20 PM
Guys, let's play nice. No need to be hostile to the OP.
Luanub #12
Posted 30 November 2012 - 08:44 PM
I still have the same problem so Im going to try re pasting the code into the computercraft computers. However it is on a server that I host. How can I open the computer so I can repaste my code. I heard that there is a program to open that specific type of program.

Any ideas?

You can open the folder for the computer on the server then paste in the files or use something like notepad++ or gedit.
The path is severfolder/world/computer/computerID/

So computer 0 would be server/world/computer/0/
ChunLing #13
Posted 02 December 2012 - 02:15 AM
Yes, that's probably the easiest way to get the correct line numbers, since you have access to those files.