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 » Scripting Helpers
Home Search
 

Re: Loops and stuff XD

Previous Thread :: Next Thread 
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 07:20 PM
Active = not Active
Current = Active
while Active == Current and HowMuch > - 9.4 do

If that is in a function, and it is called twice, shouldn't only one loop be running?

~Think Inside The Squiggles~
Report Abuse
Boomarang is not online. Boomarang
Joined: 15 Jul 2008
Total Posts: 919
31 Jul 2011 07:24 PM
If you have a nested loop then, yes, one should run until it dies, then run again. A nested loop.
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 07:26 PM
Example (PART OF SCRIPT):

function toClose()
ChangeColor("Bright red")
Active = not Active
Current = Active
while Active == Current and HowMuch < .1 do
wait(.05)
Door.CFrame = Door.CFrame + Vector3.new(0, .1, 0)
HowMuch = HowMuch + .1
end
end


function toOpen()
ChangeColor("Dark green")
Active = not Active
Current = Active
while Active == Current and HowMuch > - 9.4 do
wait(.05)
Door.CFrame = Door.CFrame - Vector3.new(0, .1, 0)
HowMuch = HowMuch - .1
end
end



toOpen()
wait(1)
toClose()

Shouldn't the loop in toOpen stop and only the one in toClose run? Because, it doesn't...
~Think Inside The Squiggles~
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 07:28 PM
Bump

~Think Inside The Squiggles~
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 07:34 PM
^

~Think Inside The Squiggles~
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 07:58 PM
Help please?

~Think Inside The Squiggles~
Report Abuse
Newtrat is not online. Newtrat
Joined: 13 Jun 2011
Total Posts: 196
31 Jul 2011 08:03 PM
I think the issue is that you're using Current as a global variable, so when you change Current in toClose it changes Current back in toOpen as well... hence Current is always equal to Active (since you set Current = Active in both functions) except for the split second in the first line of toClose... which goes by too fast for the engine to recognize the change.

Try changing the lines to
local Current = Active

or maybe renaming one of the Current variables.
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
31 Jul 2011 08:04 PM
In that case, yes, because the function is running on the same thread as the rest of the script. However, if you are doing it with events, it won't work that way, since functions called by events are run on seperate threads, so they won't interfere with the flow of the rest of the script.

~Sorcus
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 08:05 PM
Conflicting answers...

~Think Inside The Squiggles~
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
31 Jul 2011 08:06 PM
Whatever answer I give will always be the correct one. :D

~Sorcus
Report Abuse
unknown89089 is not online. unknown89089
Joined: 21 Aug 2008
Total Posts: 2961
31 Jul 2011 08:06 PM
When will I die?
Report Abuse
Newtrat is not online. Newtrat
Joined: 13 Jun 2011
Total Posts: 196
31 Jul 2011 08:12 PM
@crazypotato4: really? I would have thought that it wouldn't matter whether the functions were called by events or not; since they're in the same script the variable Current should be the same variable in both of them as the script is currently written... or anyway that's what I thought. Does it work differently because Current isn't declared as being local to the script? Do I have no idea what I'm talking about? (Maybe.)
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 08:13 PM
*Uses Newtrat's advice*

~Think Inside The Squiggles~
Report Abuse
nickmaster24 is not online. nickmaster24
Joined: 04 Oct 2008
Total Posts: 8906
31 Jul 2011 08:15 PM
Sorry crazy, but Newtrat's fix worked...

~Think Inside The Squiggles~
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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