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
 

Create a loop without using "While True Do"?

Previous Thread :: Next Thread 
CoolJohnnyboy is not online. CoolJohnnyboy
Joined: 09 Mar 2010
Total Posts: 17699
26 Jan 2015 02:45 PM
How does one do that?
Report Abuse
PixelAspect is not online. PixelAspect
Joined: 29 Jun 2009
Total Posts: 266
26 Jan 2015 02:52 PM
Lots of ways. You can use the repeat function vvv

repeat
[Code]
until false
(Looks at the wiki for more details)

You could also make a loop out of a function like vvv

function [Name]()
[Code]
[functionName]()
end
[functionName]()

(make sure to put a wait in the loop so you don't crash the game)
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 02:53 PM
@Pixel:
1) "repeat" isn't a function
2) Your recursion example would cause a stack overflow.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
26 Jan 2015 03:08 PM
As Droid said, it's better to run a loop instead of a recursion. Reason being that Lua needs memory from somewhere, and if you're filling up all the closures Lua is going to have a hard time.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 03:09 PM
Lua does support tail call recursion, though I'm not sure how good at it it is.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
26 Jan 2015 03:10 PM
It's okay, but compared to stuff like C it's not too great.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 03:14 PM
In Haskell, all you can do is recursion. No loops. If you want to do something to each element in a list, use map:

map :: (a -> b) -> [a] -> [b]
map _ [] = []
map f (x:xs) = f x : map f xs

double :: Num a => [a] -> [a]
double = map (*2)

main = do
putStrLn $ double [1..10] -- [2,4,6,8,10,12,14,16,18,20]
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
26 Jan 2015 03:15 PM
Yes but Haskell is functional, which isn't practical for games.
Report Abuse
PixelAspect is not online. PixelAspect
Joined: 29 Jun 2009
Total Posts: 266
26 Jan 2015 03:17 PM
Well sorry for giving him multiple answers to his question >.>
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 03:17 PM
Not necessarily. It compiles to machine code so it is fast, it's just very different to write in.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
26 Jan 2015 03:20 PM
Repeat
.
.
.
until 1 == 2

for i,0,math.huge
.
.
.
end -- for

but these are endless loops. What I imagine u mean is; "How do I stop a loop"?

use a condition

done = false

while not done do
.
if job_is_done then job = true; end -- job done?
.
end -- while

GL
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
26 Jan 2015 03:33 PM
function while(bool, func)
if bool == true then
return func()
end
end

while((x==5), function()
print(x)
end)


This is inefficient but it answers you question :D Then there's also the repeat/until keywords or the for/do loop.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 03:35 PM
@War: That doesn't loop, just an if without an else, and you can't call a function "while".
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
26 Jan 2015 03:48 PM
@Dr I know... You ruined my post D:
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 03:51 PM
o


while = (function()return(function(...)if(({...})[1])then return({...})[2]()end end))()
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