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

[Question] setting variables

Started by dextermb, 16 December 2012 - 03:03 AM
dextermb #1
Posted 16 December 2012 - 04:03 AM
I'd like to be able to set a variable by user input

for example


i(x)
print ("what would you like "i" to be?")
  input = read()
   input set x

now i know "input set x" isn't correct, so i wondered if anyone could help?
theoriginalbit #2
Posted 16 December 2012 - 04:10 AM
You are assigning to the variable input the value of what the user types with read()
you have answered your own question :)/>
what is the i(x) ?? o.O
dextermb #3
Posted 16 December 2012 - 04:12 AM
i is the variable that i'd like to set when someone puts in an input
theoriginalbit #4
Posted 16 December 2012 - 04:15 AM
i is the variable that i'd like to set when someone puts in an input

so in that case the code would read

i = read()

if you want to use it as a number if would read

i = tonumber(read())
dextermb #5
Posted 16 December 2012 - 04:15 AM
i is the variable that i'd like to set when someone puts in an input

so in that case the code would read

i = read()

if you want to use it as a number if would read

i = tonumber(read())

thank you sir
dextermb #6
Posted 16 December 2012 - 04:17 AM
i is the variable that i'd like to set when someone puts in an input

so in that case the code would read

i = read()

if you want to use it as a number if would read

i = tonumber(read())

update: that doesn't work, it asks for the Var before the program prints the question, why would this be?
theoriginalbit #7
Posted 16 December 2012 - 04:20 AM
i is the variable that i'd like to set when someone puts in an input

so in that case the code would read

i = read()

if you want to use it as a number if would read

i = tonumber(read())

update: that doesn't work, it asks for the Var before the program prints the question, why would this be?

Quick question here…. are you programming in Lua? on a ComputerCraft computer? I have never been asked for Var ever. can you copy paste the error?
dextermb #8
Posted 16 December 2012 - 04:30 AM
i is the variable that i'd like to set when someone puts in an input

so in that case the code would read

i = read()

if you want to use it as a number if would read

i = tonumber(read())

update: that doesn't work, it asks for the Var before the program prints the question, why would this be?

Quick question here…. are you programming in Lua? on a ComputerCraft computer? I have never been asked for Var ever. can you copy paste the error?

Computercraft computer,



i = read()
print ("Question")
input = read()
print (i)

it asks for the Var before the question :/
theoriginalbit #9
Posted 16 December 2012 - 04:33 AM
that is because the terminal pauses and waits for enter press when read() is called, use this instead.


print("Question")
i = read()
print(i)
dextermb #10
Posted 16 December 2012 - 04:47 AM
that is because the terminal pauses and waits for enter press when read() is called, use this instead.


print("Question")
i = read()
print(i)

Ok that works, the only issue is that you have to hit enter twice after putting an input in to print the "i"
theoriginalbit #11
Posted 16 December 2012 - 04:52 AM
if the code ONLY has what is above you shouldn't have to hit enter twice… is what i sent the only code in the program?
dextermb #12
Posted 16 December 2012 - 04:54 AM

function receive()
  rednet.receive()
end
shell.run("clear")
  print ("Email Program V0.01")
    write ("Email Address: ")
	  ID = read() input = read()
    write ("Message: ")
	  Message = read() input = read()
  print (ID," ", Message)
    rednet.send(ID, Message)
	  sleep(1)
  print("Message Should be sent to ", ID)

Now the issue si that rednet.send(ID, Message) isn't working ^^
theoriginalbit #13
Posted 16 December 2012 - 05:06 AM
do this EXACTLY:

side = "right" -- REPLACE WITH SIDE MODEM IS ON, all lowercase!

rednet.open(side)

function receive()
  rednet.receive() -- btw this returns the senderId, message, and distance and will wait until it gets something
end

term.clear()

print("Email Program V0.01")
write("Email Address: ")
id = tonumber( read() )
write("Message: ")
msg = read()

rednet.send( id, msg )
sleep(1)
print("Message sent to"..id)

rednet.close(side)
dextermb #14
Posted 16 December 2012 - 05:13 AM
do this EXACTLY:

side = "right" -- REPLACE WITH SIDE MODEM IS ON, all lowercase!

rednet.open(side)

function receive()
  rednet.receive() -- btw this returns the senderId, message, and distance and will wait until it gets something
end

term.clear()

print("Email Program V0.01")
write("Email Address: ")
id = tonumber( read() )
write("Message: ")
msg = read()

rednet.send( id, msg )
sleep(1)
print("Message sent to"..id)

rednet.close(side)

thnx
theoriginalbit #15
Posted 16 December 2012 - 05:13 AM
no probs.
Doyle3694 #16
Posted 16 December 2012 - 05:17 AM
that recieve function is pretty much useless….