Jump to content


Watcher7's Content

There have been 16 items by Watcher7 (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#92004 split "%" from a string

Posted by Watcher7 on 28 February 2013 - 10:35 AM in Ask a Pro

Do you mean split a string apart based on the placement of "%"s?
http://codepad.org/wlMBsKIy
str = "Hello%world%foo%bar"
tbl = {}
str:gsub("[^%%]+", (function(word) table.insert(tbl, word) end))
or (in the form of a function)
http://codepad.org/Q4QnRUyG
split_function = function(str)
    local tbl = {}
    str:gsub("[^%%]+", (function(word) table.insert(tbl, word) end))
    return tbl
end



#52541 [Lua][Help]Separating parts of a string.

Posted by Watcher7 on 22 November 2012 - 07:40 PM in Ask a Pro

View PostKingdaro, on 22 November 2012 - 07:28 PM, said:

View PostLyqyd, on 22 November 2012 - 07:18 PM, said:

If you aren't parsing a known-element-count string, you use string.gmatch and put the results into a table, which is more efficient than the split() function anyway.
gmatch alone doesn't necessarily help very well when the string is formatted with "something, something, something". Splitting functions were made with accounting for the missing delimiter at the end. The one I posted isn't the most efficient function, but as I've said, there are better implementations out there.
If you're saying string.gmatch() won't be able to handle a missing comma (or any other delimiter) at the end you are wrong.
http://codepad.org/bThNappI

EDIT:
M'kay the lack of new post notifications is annoying me even more now.
I don't like repeating what someone has posted 1 minute before I posted.



#52471 Conditional operator in lua

Posted by Watcher7 on 22 November 2012 - 12:41 PM in Ask a Pro

View PostETHANATOR360, on 22 November 2012 - 12:17 PM, said:

i mean like x = y ? 1 : 0

That's called the ternary operator.
http://codepad.org/CEtRWl6l

Kingdaro also showed you this.

EDIT: Isn't this shit supposed to alert me when someone posts something new? First the staff and recent thread frames are broken, now this.



#51153 Website addon

Posted by Watcher7 on 18 November 2012 - 05:06 PM in Suggestions

Also, if you want to do non-CC specific Lua practice you can try http://codepad.org/.
http://codepad.org also has support for languages other than Lua.



#49278 This reading is not working as hoped

Posted by Watcher7 on 12 November 2012 - 04:44 AM in Ask a Pro

Change
local recent = fileData[1], fileData[2], fileData[3], fileData[4], fileData[5]
print("Recent Activitys:"..recent)

to
local recent = ( table.concat( fileData, 'n', ( ( #fileData > 5 ) and ( #fileData - 4 ) or 1 ), #fileData ) .. 'n' )
write( "Recent activities:n" .. recent )



#48289 [SOLVED] [Lua] [Question] How to use the mouse api?

Posted by Watcher7 on 08 November 2012 - 05:50 PM in Ask a Pro

View Postaura, on 08 November 2012 - 05:49 PM, said:

Thank you!
No problem, just be sure to indent. :P/>



#48284 [SOLVED] [Lua] [Question] How to use the mouse api?

Posted by Watcher7 on 08 November 2012 - 05:24 PM in Ask a Pro

View Postaura, on 08 November 2012 - 05:15 PM, said:

Sorry, but... how do you use that event?
(Haha! Im new to this sorry!)
To get a basic understanding of os.pullEvent please refer to: http://www.computerc...1156#entry11156
After that it's up to you to decide on how to best use it.



#48278 [SOLVED] [Lua] [Question] How to use the mouse api?

Posted by Watcher7 on 08 November 2012 - 05:09 PM in Ask a Pro

Mouse information is handled via events:
http://computercraft...ent#Event_Types



#44981 [QUESTION] How to turn words into numbers

Posted by Watcher7 on 27 October 2012 - 07:40 PM in Ask a Pro

Also, there is something called coercion. Coercion in Lua basicly implies a type change during things like (addition | subtraction | division | multiplication).
EX:
> =( 1 + '1' + "1" )
3


(EDIT:
Seems like the forums didn't alert me to a new post...)



#43424 LyqydOS Beta/Development

Posted by Watcher7 on 23 October 2012 - 02:21 AM in Operating Systems

Massively hawt.



#43057 [SOLVED]Acii

Posted by Watcher7 on 22 October 2012 - 01:32 AM in Ask a Pro

You have to escape the 's.
EX:
> print(' ')

> print(' ')


's are known as 'escape characters'.
They're used for stuff like new lines ('n'), char codes ('001'), and quote escaping (''').



#37675 Error I cannot understand.

Posted by Watcher7 on 07 October 2012 - 04:12 AM in Ask a Pro

View Postbrett122798, on 07 October 2012 - 04:05 AM, said:

View PostWatcher7, on 07 October 2012 - 04:01 AM, said:

Hitting the tab key isn't that hard.
You cannot tab on CC computers, and half my code was done on one.
But CC is now able to pull from your clip-board, you should not be doing anything but quick edits in-game with edit. All your work should be done outside in your editor/IDE of choice and transfered over (or edited directly if the files are local).



#37671 Error I cannot understand.

Posted by Watcher7 on 07 October 2012 - 04:01 AM in Ask a Pro

View Postbrett122798, on 07 October 2012 - 03:58 AM, said:

View Postluanub, on 07 October 2012 - 03:53 AM, said:

Not in the case of the fs api.

A good tutorial on using fs is here
Both ways work, that is currently not my problem atm. Look above. EDIT: Last Page


EDIT: Ninja'd

View PostWatcher7, on 07 October 2012 - 03:56 AM, said:

Also, please learn to indent your code with atleast 2 spaces (4 spaces or 1 tab is more common) per block, otherwise people can't read large scripts you make and you might get lost in your own code (and get laughed at by less understanding programmers).

Example of indentation:
local indentation = {}

function indentation.example()
	local correct = true
	if correct then
		for counter = 1, 10 do
			print('This is an example of "correct" indentation.')
		end
	end
end

indentation.example()

I know, my code looks horrible, but the reason I don't is cause I think it's wasting time.
Hitting the tab key isn't that hard nor is it time consuming.



#37668 Error I cannot understand.

Posted by Watcher7 on 07 October 2012 - 03:56 AM in Ask a Pro

Also, please learn to indent your code with atleast 2 spaces (4 spaces or 1 tab is more common) per block, otherwise people can't read large scripts you make and you might get lost in your own code (and get laughed at by less understanding programmers).

Example of indentation:
local indentation = {}

function indentation.example()
	local correct = true
	if correct then
		for counter = 1, 10 do
			print('This is an example of "correct" indentation.')
		end
	end
end

indentation.example()



#37654 Error I cannot understand.

Posted by Watcher7 on 07 October 2012 - 02:56 AM in Ask a Pro

Pastebin the entire thing or be sure to thoroughly re-read your source.
It's possible that 'newusername' is not assigned (possibly from mis-typing the variable) and points to nil.
It's far easier to help you if you let us see the entire source.



#21589 [lua] [error] :35: <eof> expected

Posted by Watcher7 on 26 July 2012 - 01:40 PM in Ask a Pro

http://pastebin.com/Y9kxy062
M'kay so here's the deal, formatting is VERY important. I normally don't do this for people, but it's just formatting so there's the pastebin. But I didn't fix every-thing, I don't think I saw you define context, and I'm pretty sure shell.run takes a string, not plain-text/undefined-var.