Castillo Posted December 1, 2010 Posted December 1, 2010 hey, i have a question, i want to create a system for "goto line" like in notepad, but my question is how to? if someone could give me a example of something i will be very appreciated. Thanks in advance.
Aibo Posted December 2, 2010 Posted December 2, 2010 no idea, 'cause i dont really get what you want. labels in code? dont think thats needed.
Discord Moderators Zango Posted December 2, 2010 Discord Moderators Posted December 2, 2010 Are you creating a file editor in MTA or something?
Static-X Posted December 2, 2010 Posted December 2, 2010 Let me guess, he(Castillo/Solidsnake14) is making a notepad for his computer system resource right?
Castillo Posted December 2, 2010 Author Posted December 2, 2010 Zango got the point i'm creating a in-game script editor, so to be easier to go to a line i need something like notepad has, goto line, but my problem is how to make that? i'm using a memo btw.
Discord Moderators Zango Posted December 2, 2010 Discord Moderators Posted December 2, 2010 are lines just separated by enter? Or do they properly include \n (newline) If not, when client presses enter and the memo is in focus you could set it to secretly add \n to the string this way, you can count the amount of times \n has been used in your string, or alternatively plus a variable 'lines' by 1 each time
Castillo Posted December 3, 2010 Author Posted December 3, 2010 i open the file with fileOpen then i use fileRead and trigger it to client then guiSetText to the memo.
Castillo Posted December 4, 2010 Author Posted December 4, 2010 i've tried this, guiMemoSetCaretIndex(script_memo,tonumber(line)) but when i set to example: line 50 it doesn't sends me there but at same time when i do line 1 it moves to start of script o_O
Aibo Posted December 4, 2010 Posted December 4, 2010 i've tried this, guiMemoSetCaretIndex(script_memo,tonumber(line)) but when i set to example: line 50 it doesn't sends me there but at same time when i do line 1 it moves to start of script o_O index is not line index, its character index. you can calcutate positions of line breaks (\n) and move to the next symbol by guiMemoSetCaretIndex
Castillo Posted December 4, 2010 Author Posted December 4, 2010 oh, i suposed because i did goto line 100000 and worked , so how i can make what you say?
Aibo Posted December 4, 2010 Posted December 4, 2010 with some combination ot string functions i suppose, need to think about best way
dzek (varez) Posted December 4, 2010 Posted December 4, 2010 function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} -- for each divider found for st,sp in function() return string.find(str,div,pos,true) end do table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider return arr end local mystring = "some\ntext\nbla\nbla\nbla" -- this text have 5 lines local exp = explode("\n", mystring) local targetLine = 3 local index=0 for i=1, targetLine-1 do index = index + exp[i].len end guiMemoSetCaretIndex(memo, index) -- i have my brain overheated, maybe you will need to add 1 to index to make it work correctly (but probably not) sorry if its buggy ;]
Aibo Posted December 4, 2010 Posted December 4, 2010 function explode(div,str) https://wiki.multitheftauto.com/wiki/Split
dzek (varez) Posted December 4, 2010 Posted December 4, 2010 can be used instead, but explode will split via any string (like "i rule-:-and this is 2nd string", then explode("-:-", string)), this requires ASCII number (for new line it will be 10 BTW (or 13? but 13 was for \r afair)
Castillo Posted December 4, 2010 Author Posted December 4, 2010 i don't get how to implement your code varez in my script. btw it gives an error at this line: index = index + exp.len attempt to perform arithmetic on field 'len' (a function value) edit: fixed error, index = index + exp:len() edit2: i've tryed to implement it, question: do i have to add: local mystring = guiGetText(script_memo) local exp = explode("\n", mystring) local targetLine = tonumber ( guiGetText ( script_memo ) ) local index=0 for i=1, targetLine-1 do index = index + exp[i]:len() end guiMemoSetCaretIndex(script_memo,index) in the event when click "goto line" button? or let it external?
Aibo Posted December 5, 2010 Posted December 5, 2010 in the event when click "goto line" button? or let it external? add it as a function and call it to get index for guiMemoSetCaretIndex when "goto" button clicked: function getLineIndex(mystring, targetLine) local exp = explode("\n", mystring) local index=0 for i=1, targetLine-1 do index = index + exp[i]:len() end return index end -- onClientGUIClick your "goto line" button: guiMemoSetCaretIndex(script_memo, getLineIndex(guiGetText(script_memo), guiGetText(someLineNumberEditBox)))
Castillo Posted December 5, 2010 Author Posted December 5, 2010 (edited) i get an error: attempt to perform arithmetic on local 'targetLine' (a nil value) code: function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} for st,sp in function() return string.find(str,div,pos,true) end do table.insert(arr,string.sub(str,pos,st-1)) pos = sp + 1 end table.insert(arr,string.sub(str,pos)) return arr end local mystring = guiGetText(script_memo) local exp = explode("\n", mystring) local targetLine = tonumber ( guiGetText ( script_memo ) ) local index=0 for i=1, targetLine-1 do index = index + exp[i]:len() end function getLineIndex(mystring, targetLine) local exp = explode("\n", mystring) local index=0 for i=1, targetLine-1 do index = index + exp[i]:len() end return index end Edit: i set targetLine to 3 and no errors, i do goto line 1 and it moves to start of script, but my problem is: how i can do something to select the line? Edited December 5, 2010 by Guest
Aibo Posted December 5, 2010 Posted December 5, 2010 well i dont know how your editBox called where client puts line number to go to. replace someLineNumberEditBox with that variable function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} for st,sp in function() return string.find(str,div,pos,true) end do table.insert(arr,string.sub(str,pos,st-1)) pos = sp + 1 end table.insert(arr,string.sub(str,pos)) return arr end --[[-- you don't need this part: local mystring = guiGetText(script_memo) local exp = explode("\n", mystring) local targetLine = tonumber ( guiGetText ( script_memo ) ) local index=0 for i=1, targetLine-1 do index = index + exp[i]:len() end --]]-- since its in a function now function getLineIndex(mystring, targetLine) local exp = explode("\n", mystring) local index=0 for i=1, targetLine-1 do index = index + exp[i]:len() end return index end
Castillo Posted December 5, 2010 Author Posted December 5, 2010 it seems to work, but now about selecting the text, how i can do this? is possible?
Aibo Posted December 5, 2010 Posted December 5, 2010 i dont think it is, not in an easy way at least.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now