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

Window 57: Number expected help!

Started by Gumball, 18 September 2014 - 04:13 AM
Gumball #1
Posted 18 September 2014 - 06:13 AM
So, im making a website thing that sends and receives data, and I have the server setup, but the client isn't working, so its receiving a text and background packet, i said print the table part, and it printed what I wanted to see but whenever I use it in term.setBackgroundColor(serverData[1]) its not working :(/>. heres the code for both the server and client, pls focus on the client mainly:

Client:

rednet.open("top")
rednet.broadcast("")

id, message = rednet.receive()

websiteData = textutils.serialize(message)

website = textutils.serialize(message)

local serverData = {
  [1] = (message[1])
}

term.setBackgroundColor(serverData[1])
term.clear()

Server:

os.unloadAPI("api")
rednet.open("top")

id, message = rednet.receive()

local websiteTitle = {
  [1] = ("website.com"),
  [2] = ("Welcome to the test website!")
}

local websiteData = {
  [1] = ("colors.gray"), --background color
  [2] = ("colors.blue") --text main color
}

local errorPackets = {
  [1] = ("Unknown data request, disconnecting"),
  [2] = ("Error proccessing data."),

  [3] = ("There was 1 or 2 errors proccessing data,"),
  [4] = ("so we could not send anymore data to you.")
}

function transmitPacket(data)
  rednet.send(id,data)
end

function unknownDataRequest()
  rednet.send(id,errorPackets)
end

transmitPacket(websiteData)
Edited on 18 September 2014 - 04:14 AM
KingofGamesYami #2
Posted 18 September 2014 - 01:18 PM
This is because you are attempting to set the color to a string…


local websiteData = {
  [ 1 ] = "colors.gray",
  [ 2 ] = "colors.blue".
}
--#doesn't work!  Use the number values for it to work
local websiteData = {
  [ 1 ] = colors.gray,
  [ 2 ] = colors.blue,
}

Edit: Fixed the - thing pointed out by bomb bloke… happens when I type too fast.
Edited on 19 September 2014 - 12:19 AM
Gumball #3
Posted 19 September 2014 - 12:59 AM
This is because you are attempting to set the color to a string…


local websiteData = {
  [ 1 ] = "colors.gray",
  [ 2 ] = "colors.blue".
}
--#doesn't work!  Use the number values for it to work
local websiteData - {
  [ 1 ] = colors.gray,
  [ 2 ] = colors.blue,
}

Didn't work. next time try your code before posting?
Edited on 18 September 2014 - 11:06 PM
KingofGamesYami #4
Posted 19 September 2014 - 01:30 AM
This is because you are attempting to set the color to a string…


local websiteData = {
  [ 1 ] = "colors.gray",
  [ 2 ] = "colors.blue".
}
--#doesn't work!  Use the number values for it to work
local websiteData - {
  [ 1 ] = colors.gray,
  [ 2 ] = colors.blue,
}

Didn't work. next time try your code before posting?

I did. <_</>


term.setTextColor( colors.gray )
term.setTextColor( "colors.gray" )

Try using tonumber on the other end as well…

term.setBackgroundColor( tonumber( serverData[ 1 ] ) )

Or, you could do this:


--#send this value:
bColor = "gray"
--#use this on the other side:
term.setTextColor( colors[ bColor ] )
Edited on 18 September 2014 - 11:34 PM
Bomb Bloke #5
Posted 19 September 2014 - 01:41 AM
Try using tonumber on the other end as well…

There's no need to do that, and nothing wrong with the initial change you suggested… except for your use of a "-" instead of an "=", which I'd hope bluebird173 spotted and corrected under his own initiative. Hard to say. He didn't bother to post what happened when he tried it.