smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 26 Mar 2012 06:51 PM |
So I was working on making my own custom events and it got me thinking. Just how much better are events compared to loops? I know some events - Touched, MouseButton1Down, Chatted - would be hard, _if possible_, to reproduce, but when you look at things liike Changed and MouseEnter, just how much of a difference is there between using loops and events? Events would probably be coded in C and more effecient than if it were otherwise, but if they were coded in Lua would it stilll be better to use events over loops?
Take this for example -
local base = Workspace.Base
coroutine.resume(couroutine.create(function() while base.Name == "Base" and wait(__time__) do end print("Base's name has been changed to "..base.Name) end)) ---------------------or a repeat coroutine.resume(couroutine.create(function() repeat wait(__time__) until base.Name ~= "Base" print("Base's name has been changed to "..base.Name) end))
over an event
base.Changed:connect(function(prop) --Would be more like base.Changed:wait() but just an example print("Base's "..prop.." has been changed to "..base[prop]) end)
As you can see they are both doing the same thing but is a event really that much better? As far as I'm concerned the event 1) checks to see if the condition is true (Bases properties have been changed) 2) If true fires the function 3) if false skips a frame and returns to 1
The loop is doing pretty much the exact same thing in a more direct way. I'm not trying to saying you should abandon using events , but I'd like to know what you think. Are events really that much better than loops or is there a reason whhy events would still be better? (Besides the point of readability/languages) |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 26 Mar 2012 06:54 PM |
while wait() do end
That right puts absolutely no stress on performance, which stravant said a while back (I hate using him as a source, but without some form you get a whole bunch of amateurs starting a useless debate).
All events are faster than recreating them. Period. This is because they are all embedded with code from the C-side. Which we all know is faster than using plain Lua. |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 26 Mar 2012 07:11 PM |
"(Besides the point of readability/languages)"
I know events would be faster than normally recreating them, but this is going off the idea that events are coded in lua |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 26 Mar 2012 07:14 PM |
| If that were true than the question answers itself. There wouldn't be much of a difference. |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 26 Mar 2012 07:20 PM |
You're no fun at all :P "but I'd like to know what you think. Are events really that much better than loops or is there a reason whhy events would still be better? "
I was hoping to get more of a discussion w/ view points but I guess I should've expected as much. |
|
|
| Report Abuse |
|
|