Jump to content




Window 57: Number expected help!


  • You cannot reply to this topic
4 replies to this topic

#1 Gumball

  • Members
  • 254 posts
  • LocationFairbanks, Alaska

Posted 18 September 2014 - 05: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 by bluebird173, 18 September 2014 - 05:14 AM.


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 18 September 2014 - 12: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 by KingofGamesYami, 19 September 2014 - 01:19 AM.


#3 Gumball

  • Members
  • 254 posts
  • LocationFairbanks, Alaska

Posted 18 September 2014 - 11:59 PM

View PostKingofGamesYami, on 18 September 2014 - 12:18 PM, said:

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 by bluebird173, 19 September 2014 - 12:06 AM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 19 September 2014 - 12:30 AM

View Postbluebird173, on 18 September 2014 - 11:59 PM, said:

View PostKingofGamesYami, on 18 September 2014 - 12:18 PM, said:

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 by KingofGamesYami, 19 September 2014 - 12:34 AM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 September 2014 - 12:41 AM

View PostKingofGamesYami, on 19 September 2014 - 12:30 AM, said:

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users