Jump to content




Help


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

#1 Leon669

  • Members
  • 57 posts
  • LocationGermany

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 by Leon669, 27 February 2015 - 05:46 PM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 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.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited 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


#4 Leon669

  • Members
  • 57 posts
  • LocationGermany

Posted 27 February 2015 - 06:14 PM

View PostKingofGamesYami, on 27 February 2015 - 06:07 PM, said:

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?

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited 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.

#6 valithor

  • Members
  • 1,053 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.

#7 Leon669

  • Members
  • 57 posts
  • LocationGermany

Posted 28 February 2015 - 05:11 PM

View PostKingofGamesYami, on 27 February 2015 - 06:55 PM, said:

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 ...

#8 valithor

  • Members
  • 1,053 posts

Posted 28 February 2015 - 06:07 PM

View PostLeon669, on 28 February 2015 - 05:11 PM, said:

View PostKingofGamesYami, on 27 February 2015 - 06:55 PM, said:

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 by valithor, 28 February 2015 - 06:08 PM.


#9 Leon669

  • Members
  • 57 posts
  • LocationGermany

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 by Leon669, 28 February 2015 - 06:39 PM.


#10 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 01 March 2015 - 01:31 AM

View PostLeon669, on 28 February 2015 - 06:18 PM, said:

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.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users