56 posts
Location
Germany
Posted 27 February 2015 - 05:16 PM
How can i update a clock every second in a menu ?
generelly question how can i but such a function
How can i read a specific line with file.readLine() ?
is there a way to get (exp. to line 3 or so on?)
How can i choose more than one coordinates in
if XY == "8,7" and button == 1 then
Thx a lot
Edited on 27 February 2015 - 04:46 PM
8543 posts
Posted 27 February 2015 - 05:35 PM
You should really use a more descriptive topic title. Please post the code you're having problems with. You'll have to read all the previous lines of the file in order to get to a specific line with readLine.
3057 posts
Location
United States of America
Posted 27 February 2015 - 06:07 PM
I wonder where you'd come across "X,Y", because you can't compare that way.
You'd have to compare like this:
if x == 8 and y == 7 and button == 1 then
To get a specific line, you'll have to move through each line until you hit the one you want, like this:
local i, line = 1
repeat
line = file.readLine()
i = i + 1
until i == 3
56 posts
Location
Germany
Posted 27 February 2015 - 06:14 PM
I wonder where you'd come across "X,Y", because you can't compare that way.
You'd have to compare like this:
if x == 8 and y == 7 and button == 1 then
To get a specific line, you'll have to move through each line until you hit the one you want, like this:
local i, line = 1
repeat
line = file.readLine()
i = i + 1
until i == 3
while true do
local event, button, X, Y = os.pullEvent("mouse_click")
XY = X..","..Y
—————————————————
if x == 1 and y == 1 and button == 1 then
shell.run"clear"
shell.run"desktop"
end
doesnt works with that function how have the function to be?
3057 posts
Location
United States of America
Posted 27 February 2015 - 06:55 PM
while true do
local event, button, x, y = os.pullEvent( "mouse_click" )
if x == 1 and y == 1 and button == 1 then
shell.run( "clear" )
shell.run( "desktop" )
end
end
…should work. All you're missing is a second end.
1023 posts
Posted 27 February 2015 - 07:10 PM
He also has different capitalization of his variables. He has X,Y = os.pullEvent and then is checking against x and y.
56 posts
Location
Germany
Posted 28 February 2015 - 05:11 PM
while true do
local event, button, x, y = os.pullEvent( "mouse_click" )
if x == 1 and y == 1 and button == 1 then
shell.run( "clear" )
shell.run( "desktop" )
end
end
…should work. All you're missing is a second end.
while true do
local event, button, x, y = os.pullEvent( "mouse_click" )
if x == 1 , 2 and y == 1 and button == 1 then
shell.run( "clear" )
shell.run( "desktop" )
end
end
not working …
1023 posts
Posted 28 February 2015 - 06:07 PM
while true do
local event, button, x, y = os.pullEvent( "mouse_click" )
if x == 1 and y == 1 and button == 1 then
shell.run( "clear" )
shell.run( "desktop" )
end
end
…should work. All you're missing is a second end.
while true do
local event, button, x, y = os.pullEvent( "mouse_click" )
if x == 1 , 2 and y == 1 and button == 1 then
shell.run( "clear" )
shell.run( "desktop" )
end
end
not working …
To get multiple points you will want to use the < and > operators.
while true do
local event, button, x, y = os.pullEvent("mouse_click")
if x >=1 and x<=5 and y == 1 and button == 1 then
shell.run("clear")
shell.run("desktop")
end
end
What this will do is check if x is greater than or equal to 1 and if x is less than or equal to 5 and y is equal to one and it was button 1.
For example if x is 3 then it will return true and run the if statement, but if x is above 5 or less than 1 it will not.
Btw. if you write [.code] at the beginning of your code and [./code] at the end without the .'s it will put it in the code block like the code I posted.
Edited on 28 February 2015 - 05:08 PM
56 posts
Location
Germany
Posted 28 February 2015 - 06:18 PM
Thx so much befor i have to programm every pixel ..
now the next problem how do several pixels with paintutils.drawPixel(1,1,300) mark?
and how create a clock in a menu that updates every second ?
Edited on 28 February 2015 - 05:39 PM
3057 posts
Location
United States of America
Posted 01 March 2015 - 01:31 AM
how create a clock in a menu that updates every second ?
Creating a clock is pretty simple, os.time() returns the time. So for an updating clock, you'd do something like this:
local id = os.startTimer( 1 )
while true do
local event = { os.pullEvent() }
if event[ 1 ] == "timer" and event[ 2 ] == id then
id = os.startTimer( 1 )
term.setCursorPos( 1, 1 )
term.write( os.time() )
end
end
I have, of course, written this assuming you want to accept input alongside it in a standard event loop.