I need to "read" a line by it pos , like this:
str = "why you do that?"
3rd_word = findbypos(9,10)
print(3rd_word)
return:
"do"
local myString = "This is a string"
local str = myString:find(6,7) --#Can be string.find(myString,6,7)
print(str)
--# "is"
That except it's sub not find.string.findlocal myString = "This is a string" local str = myString:find(6,7) --#Can be string.find(myString,6,7) print(str) --# "is"
local myString = "This is a string"
local str = myString:sub(6,7) --#Can be string.sub(myString,6,7)
print(str)
--# "is"
local x, y = 1, 1
term.clear() --# Clear the screen
local file = fs.open( "<filename>", "r" )
for line in file.readLine do -- #Loop through all the lines in the file
term.setCursorPos( x, y ) --# Set the cursor position
term.write( line ) --# Write the line
y = y + 1
end
If I'm incorrect then please explain further on what you meant
--# Store all lines in a table
local lines = {}
--# Get all the lines from the file
local file = fs.open( "<your file>", "r" )
for line in file.readLine do
table.insert( lines, line )
end
--# This function will loop through all the lines
--# And check if it can find the specific word in any line
--# It will return a table like this: { x1 = 1, x2 = 2, y = 1 }
local function find( word )
local results = {}
for i, v in pairs( lines ) do --# Loop through all the lines
if line:find( word ) then --# Check and see if you can find the specific word in the line
local x1, x2 = line:find( word ) --# Get the first and last position of the word
table.insert( results, {
x1 = x1;
x2 = x2;
y = i;
})
end
end
end
local results = find( "Hello" )
print( textutils.serialize( results ) )
This is just an example, if you understood what I did here then it can probably be helpful to you, the question is, do you want to find a word by it's position? or do you want to search for it as a string( string.find( str, str2 ) )Have an error on the line if line:find( word ) then or its me?Hmm.. So you'd probably want todo something like thisThis is just an example, if you understood what I did here then it can probably be helpful to you, the question is, do you want to find a word by it's position? or do you want to search for it as a string( string.find( str, str2 ) )--# Store all lines in a table local lines = {} --# Get all the lines from the file local file = fs.open( "<your file>", "r" ) for line in file.readLine do table.insert( lines, line ) end --# This function will loop through all the lines --# And check if it can find the specific word in any line --# It will return a table like this: { x1 = 1, x2 = 2, y = 1 } local function find( word ) local results = {} for i, v in pairs( lines ) do --# Loop through all the lines if line:find( word ) then --# Check and see if you can find the specific word in the line local x1, x2 = line:find( word ) --# Get the first and last position of the word table.insert( results, { x1 = x1; x2 = x2; y = i; }) end end end local results = find( "Hello" ) print( textutils.serialize( results ) )
Edit: Try creating a file and put some random text in it, and put Hello somewhere in it and see if it returns the result you expect it to return
Is your question actually "how do I check on what text the user clicked on the screen"? If so, that's impossible. You should keep the coordinates of printed text yourself, and then use the data of the mouse_click event to find out what text was clicked.
Is your question actually "how do I check on what text the user clicked on the screen"? If so, that's impossible. You should keep the coordinates of printed text yourself, and then use the data of the mouse_click event to find out what text was clicked.
I am tryng to find a word coordenates and then check if the cursor clicked on itIs your question actually "how do I check on what text the user clicked on the screen"? If so, that's impossible. You should keep the coordinates of printed text yourself, and then use the data of the mouse_click event to find out what text was clicked.
It is possible, but as flaghacker pointed out, it's something that won't work that great. You would actually want a system that's more advanced than this. You could go with how HTML does this (and many other GUI frameworks), by having each object (a button, textbox or simply text) be a separate object. I'm talking about an Object-Oriented Programming (OOP) approach. It's really something that might not be as easy as you might expect, so my suggestion would be to first make some simpler programs, like a door lock with clickable buttons on a monitor. Also, you could look and see how different button APIs handle buttons.