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

Emailing program

Started by scarface7454, 22 November 2012 - 06:51 AM
scarface7454 #1
Posted 22 November 2012 - 07:51 AM
so im working on an emailing program for me and my friends to use on our private server. i guess im using lua….

now im using 2 seperate computers both with wireless modems as test dummies. right now i have my code to prompt the user to type in their message, then they are prompted to put in the ID to be sent to.


it seems i cant get the program to read the number thats punched for the ID or im entering the ID wrong(?) the 24 i know signifies the line of code thats bugged.

here is that line:

id = to number (id)

if need be ill learn how to add spoilers and put the whole script in.

the purpose of this thread was for one problem and now i feel like im flooding :X


i dont see many email threads up for this kind of program so im going to post my code WiP that needs some major help lol.

im now stuck at getting the message to load on the other computer. as far as i know its sending now but i cant receive, i think that part of my code needs work.

Spoiler

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

clear()

rednet.open("back") -- side the modem is on.

print("1. Send message")
print("2. Wait for message")
print("3. Exit program")

while true do
event, key = os.pullEvent("char")


if key == "1" then
  clear()
  write("Message: ")
  text = read()
  write("ID to send to: ")
  id = read()
  id = tonumber(read())
  rednet.send( id, message)
  print("Message sent")
  sleep(1)
  shell.run("email")

elseif key == "2" then
  clear()
  print("waiting for message")
  print("press enter to abort")
  while true do
   event, param1, param2 = os.pullEvent()
   if event == "rednet_message" then
	print("ID "..param1..": "..param2)
	shell.exit()
   elseif event == "char"  and param1 == "enter" then
	write("Aborted")
	shell.exit
   end
  end
elseif key == "3" then
  print("Exiting program")
  shell.exit()
end
end
bjornir90 #2
Posted 22 November 2012 - 08:00 AM
so im working on an emailing program for me and my friends to use on our private server. i guess im using lua….

right now im using 2 seperate computers both with wireless modems as test dummies. right now i have my code to prompt the user to type in their message, then they are prompted to put in the ID to be sent to.

and thats where I get email 24 attempt to call nil

it seems i cant get the program to read the number thats punched for the ID or im entering the ID wrong(?) the 24 i know signifies the line of code thats bugged.

here is that line:

id = to number (id)

if need be ill learn how to add spoilers and put the whole script in.
It's tonumber() without spaces :(/>/>
Zudo #3
Posted 22 November 2012 - 08:04 AM
to do a spoiler do
(in square brackets not rounded):
(spoiler)
STUFF
(/spoiler)
Example
SpoilerSTUFF
scarface7454 #4
Posted 22 November 2012 - 08:18 AM
thank you guys :(/>/>

bad arguement #1: value expected?

:X

im not sure why its not reading the value i type in….

here is the string

if key == "1" then
  clear()
  write("Message: ")
  text = read()
  write("ID to send to: ")
  id = read()
  id = tonumber()
  rednet.send( id, text)
  print("Message Sent")
  sleep(1)
  shell.run("email")

is it because text - read() and id = read() ?
remiX #5
Posted 22 November 2012 - 08:38 AM
Have you declared 'key'?
and do:
id = tonumber(read())
scarface7454 #6
Posted 22 November 2012 - 08:39 AM
You'll have to excuse me lack of knowledge but what do you mean declared "key"? and ill try that second park remiX
remiX #7
Posted 22 November 2012 - 08:44 AM
Well you're comparing key with "1". But what is 'key'?
scarface7454 #8
Posted 22 November 2012 - 08:50 AM
keyboard keys as far as i understand. and how it seems to be working.
remiX #9
Posted 22 November 2012 - 08:55 AM
Oh then you need to use os.pullEvent()


e, p1 = os.pullEvent()
if e == "key" and p1 == keys.x   -- So this will only trigger if you click 'x'
   term.clear()
   term.setCursorPos(1,1)
   write("Message: ")
   text = read()
   write("ID to send to: ")
   id = tonumber(read())
   rednet.send(id, text)
   print("nMessage Sent")
   sleep(1)
   shell.run("email")
end
billysback #10
Posted 22 November 2012 - 09:09 AM
As said before, please put your code in code brackets:

[code]
<code>
[*/code]
(no *)

Just makes it easier for people to help you :(/>/>
scarface7454 #11
Posted 22 November 2012 - 09:13 AM
im so sorry im lost to all this, call me mega nub of the day. thank you for not being harsh on me though.