generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: If statements / Events.

Previous Thread :: Next Thread 
Goulstem is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
03 Jun 2015 04:50 PM
Garbage collected
Report Abuse
cntkillme is not online. 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 is not online. 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 is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Jun 2015 04:56 PM
whatever ~= nil and whatever ~= false
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
03 Jun 2015 04:57 PM
Oh, well, dang, what's garbage collected?
Report Abuse
ShungTzu is not online. ShungTzu
Joined: 14 Jun 2014
Total Posts: 959
03 Jun 2015 04:58 PM
~=false, right, my bad.
Report Abuse
cntkillme is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image