34 posts
Posted 20 October 2015 - 09:30 PM
Is there a way to take an input from write?
Whenever i use read(), it only takes user input,
I want to be able to receive input from my program use write.
term.clear()
term.setCursorPos(1,1)
print("1 2 3")
print("4 5 6")
print("7 8 9")
print("+ -")
print("* /")
while true do
local event, button, x, y = os.pullEvent("mouse_click")
if x == 1 and y == 1 then
write("1")
elseif x == 3 and y == 1 then
write("2")
input = read()
end
end
7083 posts
Location
Tasmania (AU)
Posted 20 October 2015 - 10:46 PM
No, you can't get any information from write(), and I'm not sure I understand why you'd want to. Why not just do "input = 2", if you already know the user clicked on the number 2?
34 posts
Posted 20 October 2015 - 10:51 PM
I wanted it to be so that if I clicked 1 it would display 1, then if I clicked 2 it would display 12, then I wanted to take that information and make it a variable.
3057 posts
Location
United States of America
Posted 20 October 2015 - 11:06 PM
You could use
concating to add the variables together.
An example:
local var = ""
while true do
local input = read()
var = var .. input
print( var )
end
Edited on 20 October 2015 - 09:06 PM
212 posts
Location
Somewhere in this dimension... I think.
Posted 20 October 2015 - 11:10 PM
term.clear()
term.setCursorPos(1,1)
print("1 2 3")
print("4 5 6")
print("7 8 9")
print("+ -")
print("* /")
while true do
numstore = ""
local event, button, x, y = os.pullEvent("mouse_click")
if x == 1 and y == 1 then
numstore = numstore.."1"
elseif x == 3 and y == 1 then
numstore = numstore.."2"
end
end
I would also recommend speeding up the translation of mouseclick to number, though not sure how would be the best way.
And remember to tonumber(numstore) Generally math autoconverts numbers I believe.
Edited on 20 October 2015 - 09:13 PM
3057 posts
Location
United States of America
Posted 20 October 2015 - 11:11 PM
Please note that TYKUHN2's code will not work because he has declared numstore as local to the while loop.
212 posts
Location
Somewhere in this dimension... I think.
Posted 20 October 2015 - 11:13 PM
I intenteded the while true do loop to overwrite it when he is done with the number, I forgot it would overwrite it every iteration. Fixing.
34 posts
Posted 21 October 2015 - 12:08 AM
alright, got that working, but I have a new problem.
function draw()
term.clear()
term.setCursorPos(1,1)
print("1 2 3")
print("4 5 6")
print("7 8 9")
print("+ -")
print("* /")
end
draw()
ns = 0
while true do
local event, button, x, y = os.pullEvent("mouse_click")
if x == 1 and y == 1 then
ns = ns.."1"
draw()
print(ns)
end
end
If I use this, it adds a zero to the beginning, if I leave ns empty or use nil i get an error about adding to nil. (I know why it adds a zero i just want to know how to remove it, from the variable entirely)
34 posts
Posted 21 October 2015 - 01:32 AM
figured it out.
3057 posts
Location
United States of America
Posted 21 October 2015 - 01:37 AM
Just in case anyone is reading this at a later date, the solution would be to set ns to an empty string, like this:
local ns = ""
34 posts
Posted 21 October 2015 - 02:31 AM
So! it is done! First, type this into your pocket computer, or any computer
pastebin get 0wkqTE1A calc
then type
edit startup
then type,
shell.run("calc")
save and exit, then reboot.