Jump to content




Problem with rednet sending


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

#1 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 05:10 PM

rednet.open("back")
term.clear()
term.setCursorPos(9,2)
print("Would you like to launch a missile?")
term.setCursorPos(23,9)
print("Y/N")
event, p1 = os.pullEvent("key")
if p1 == 21 then
term.setCursorPos(19,10)
write("Printing Codes")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
lcode = tostring( math.random(100000,999999) )
rednet.send(3,lcode) --attempt to index ? (a nil value)
printer.write(lcode)
printer.setPageTitle("LAUNCH CODE")
printer.endPage()
term.setCursorPos(19,10)
term.clearLine()
term.setCursorPos(19,10)
print("Completed!")
sleep(2)
rednet.broadcast(lcode)
shell.run("startup")
elseif p1 == 49 then
term.setCursorPos(19,18)
print("Aborted!")
sleep(3)
shell.run("startup")
end
Please tell what I did wrong with it
Also, are you able to make the computer text be colored in the console or do you have to use the config?

#2 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 13 October 2012 - 05:31 PM

You forgot to put parenthesis after rednet.send() on the line above it.

#3 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 05:39 PM

I made it rednet.send(2,lcode) and now its erroring me whenever the program reaches that line of code.


The error: rednet:350:string expected

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 13 October 2012 - 05:55 PM

That would be because you never declare 'lcode'. Is this the whole code you're using, or only part of it?

#5 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 06:18 PM

I did!

lcode is whatever the math.random generates

#6 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 13 October 2012 - 06:20 PM

look on the line above lcode = math.random(100000, 99999999) and you will notice that you have a rednet.send() witch is missing the (), the id, and the msg

#7 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 13 October 2012 - 06:25 PM

You need to declare lcode before trying to call it. Just reverse the order. i.e. putting math.random() before rednet.send().

*edit: Lyqyd, you've been :)/> 'd

#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 13 October 2012 - 06:26 PM

 sjele, on 13 October 2012 - 06:20 PM, said:

look on the line above lcode = math.random(100000, 99999999) and you will notice that you have a rednet.send() witch is missing the (), the id, and the msg

Look a few posts up, he said he changed that.

 Kadecamz, on 13 October 2012 - 06:18 PM, said:

I did!

lcode is whatever the math.random generates

So how can you rednet.send that out before the line that generates it?

#9 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 06:50 PM

I fixed that too, but still getting the error rednet:350:string expected

current code
rednet.open("back")
term.clear()
term.setCursorPos(9,2)
print("Would you like to launch a missile?")
term.setCursorPos(23,9)
print("Y/N")
event, p1 = os.pullEvent("key")
if p1 == 21 then
term.setCursorPos(19,10)
write("Printing Codes")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
lcode = math.random(100000,999999)
rednet.send(3,lcode)
printer.write(lcode)
printer.setPageTitle("LAUNCH CODE")
printer.endPage()
term.setCursorPos(19,10)
term.clearLine()
term.setCursorPos(19,10)
print("Completed!")
sleep(2)
rednet.broadcast(lcode)
shell.run("startup")
elseif p1 == 49 then
term.setCursorPos(19,18)
print("Aborted!")
sleep(3)
shell.run("startup")
end


#10 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 13 October 2012 - 06:53 PM

 Kadecamz, on 13 October 2012 - 06:50 PM, said:

I fixed that too, but still getting the error rednet:350:string expected

current code
rednet.open("back")
term.clear()
term.setCursorPos(9,2)
print("Would you like to launch a missile?")
term.setCursorPos(23,9)
print("Y/N")
event, p1 = os.pullEvent("key")
if p1 == 21 then
term.setCursorPos(19,10)
write("Printing Codes")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
lcode = math.random(100000,999999)
rednet.send(3,lcode)
printer.write(lcode)
printer.setPageTitle("LAUNCH CODE")
printer.endPage()
term.setCursorPos(19,10)
term.clearLine()
term.setCursorPos(19,10)
print("Completed!")
sleep(2)
rednet.broadcast(lcode)
shell.run("startup")
elseif p1 == 49 then
term.setCursorPos(19,18)
print("Aborted!")
sleep(3)
shell.run("startup")
end

Do:
lcode = tostring( math.random(100000,999999) )


#11 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 07:06 PM

Now I'm getting a problem on line 19.

It says attempt to index ? a nil value

#12 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 13 October 2012 - 07:20 PM

That'd be because you never declared 'printer'. It's like monitors, you have to peripheral.wrap() the side to that variable before you can use it.

#13 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 07:39 PM

Yay!
Its working now.

But I have one more question, can you erase printed pages?
and how do you randomly generate a letter?

#14 cant_delete_account

  • Members
  • 484 posts

Posted 13 October 2012 - 07:48 PM

 Kadecamz, on 13 October 2012 - 07:39 PM, said:

Yay!
Its working now.

But I have one more question, can you erase printed pages?
and how do you randomly generate a letter?
Make a table of the alphabet like this:
local alphabet = {"a","b","c","etc"}
Then use this code to print a random letter out of it:
print(alphabet[math.random(1,#alphabet)])
So final code:
local alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
print(alphabet[math.random(1,#alphabet)])
And the alphabet does not have to be in order.

#15 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 07:59 PM

Wait, but how do I do a mix of letters AND numbers, and then put it into a string to print?

#16 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 13 October 2012 - 09:15 PM

Numbers can also be entered into tables.
table = {"1","2","3","4","5","a","b","c","d","e"}
Works just fine. I made the numbers strings, but they can be plain numbers too. Like {1,2,3}

#17 Kadecamz

  • New Members
  • 113 posts

Posted 13 October 2012 - 11:22 PM

woops, rather dumb I didn't think about that.

#18 Kadecamz

  • New Members
  • 113 posts

Posted 14 October 2012 - 12:01 AM

uhg.
guys, how do I get it to randomize six characters?
i dont want the codes being a single letter.

#19 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 14 October 2012 - 12:06 AM

Maybe a for loop?

code = {}
for i = 1,6 do
code[i] = math.random(0,9)
end

Didn't test it, but it should work.

*edit: Upon seeing Fatal_Exception's post, I know how to give a table for that. Depending on what you need.
char = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"}
for i = 1,6 do
code[i] = char[math.random(1,#char)]
end

Again, Untested, but will work, unless you want to display it, in which case, listen to F_E below.

By the way, out of curiosity, is this for generating a code for your missiles, or cracking one?

#20 Fatal_Exception

  • New Members
  • 105 posts

Posted 14 October 2012 - 12:07 AM

Repeat the process multiple times (in a for loop) and concatenate your result to the previous.

local alphabet = { (a table of characters here) }
local str = ""
for i = 1, 6 do
  str = str .. alphabet[math.random(1,#alphabet)]
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users