Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 03 Jun 2015 04:23 PM |
Pretty much the whole time I've been scripting I've thought that if statements don't effect whether or not an event fires.
local derp = false
if derp then thing.Touched:connect(function() end) end
So in the above code the Touched event will fire reguardless of what 'derp' is..
But I was reading over some code and saw this.. and it worked? If it makes any difference it was also being used in the spawn function.. I've never used the spawn function so idk if it affects anything..? Probably not.
local derp = false
spawn(function() if derp then thing.Touched:connect(function() end) end end)
Above code makes it so Touched event Doesn't fire?? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Jun 2015 04:24 PM |
The way events work is once they are 'connected', they'll fire no matter what. So when derp starts off true, the event is connected and will always fire even if derp is false. So your original code would do what you think: 'if derp is not false and not nil, connect event' |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 03 Jun 2015 04:35 PM |
| Effects don't just happen, they're effected when affected by some external cause. Remember "Cause before effect". You can't have the effect without the affect. eg: ...statements don't affect... |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 03 Jun 2015 04:44 PM |
| So.. if statements *initially* can make it so events don't connect? But once they are connected then they're never disconnected without the disconnect function. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Jun 2015 04:44 PM |
Yeah but you can always disconnect it. I think if the enclosing function is GC'd, the event is disconnected. |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 03 Jun 2015 04:49 PM |
Yes, if you want it the other way, put it inside the connected function.
What's GC'd? |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Jun 2015 04:50 PM |
| garbage collected (I should have said closure, not function but whatever) |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 03 Jun 2015 04:55 PM |
Also, with "if derp", it's true that it doesn't matter what derp is, as long as long as derp really IS (ie: that it's not nil or false) because, then, derp is not.
"if whatever" is the same as asking "if whatever~=nil" or "if whatever==true". |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Jun 2015 04:56 PM |
| whatever ~= nil and whatever ~= false |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 03 Jun 2015 04:57 PM |
Oh, well, dang, what's garbage collected?
|
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 03 Jun 2015 04:58 PM |
| Well actually now that I think about it, I doubt what I said is true unless Roblox specifically handled it like that. |
|
|
| Report Abuse |
|
|