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
 

Lua timing

Previous Thread :: Next Thread 
landie456 is not online. landie456
Joined: 17 Sep 2010
Total Posts: 451
22 Jan 2012 08:25 PM
Well i feal really noob coming here for help but scripting help is filt with RBX.Lua n00bs so you people are more likely to know what im talking about. I require a pause function in normal lua a bit like the wait() in RBX.Lua but i have beed unable to find anything like that, so could you please point me to a libray or plugin that suports somthing like that?
Report Abuse
ENET is not online. ENET
Joined: 01 Jan 2010
Total Posts: 4820
22 Jan 2012 08:27 PM
function wait(time)
local start = tick();
repeat wait(); until tick()-start >= time
return tick()-start;
end
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
22 Jan 2012 08:28 PM
@ENET

There is no such thing as tick() in normal Lua.
Report Abuse
ENET is not online. ENET
Joined: 01 Jan 2010
Total Posts: 4820
22 Jan 2012 08:28 PM
I meant....

function wait(time)
local start = tick();
repeat until tick()-start >= time
return tick()-start;
end
Report Abuse
ENET is not online. ENET
Joined: 01 Jan 2010
Total Posts: 4820
22 Jan 2012 08:29 PM
Well replace it with the unix time function. Not that hard.... Got it? K great :)>
Report Abuse
landie456 is not online. landie456
Joined: 17 Sep 2010
Total Posts: 451
22 Jan 2012 08:37 PM
Well it gives me this
name or '...' expected near '2'
so im gessuing I did it wrong by doing thing
function wait(2)
local start = tick();
repeat until tick()-start >=2
return tick()-start;
end
(brackets that looked like this < where srounding name roblox thought it was HTML)
Report Abuse
landie456 is not online. landie456
Joined: 17 Sep 2010
Total Posts: 451
22 Jan 2012 08:40 PM
Nvm Thanks ENET
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
22 Jan 2012 09:53 PM
Use yield and coroutines to make a scheduler. This will work as expected:


local ThreadList = {}

function wait(t)
t = t or -1
coroutine.yield(t)
end

function Spawn(f)
ThreadList[coroutine.create(f)] = -1
end

function Start()
while true do
local time = os.time()
for thread, resumeAt in pairs(ThreadList) do
if time >= resumeAt then
local st, resumeIn = coroutine.resume(thread)
if not st then
--error occurred
print("Error: "..tostring(resumeIn))
ThreadList[thread] = nil

elseif coroutine.status(thread) == 'dead' then
--remove it
ThreadList[thread] = nil

else
--set when to resume
ThreadList[thread] = time+(resumeIn or -1)
end
end
end
end
end

Spawn(function()
print("Hello, World...")
for i = 1, 10 do
wait(1)
print("..."..i)
end
end)

Spawn(function()
wait(5)
print("In 5.")
a.b = 7
end)

Start()
Report Abuse
michael1784 is not online. michael1784
Joined: 15 Feb 2011
Total Posts: 3322
22 Jan 2012 10:19 PM
Dang Stravant O_O I. might use that..
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
22 Jan 2012 10:26 PM
@Stravent, he wanted one for Lua, not rbx.lua.

" I require a pause function in normal lua a bit like the wait() in RBX.Lua"

Don't think it's possible writing a wait function that *works* like roblox's would.

­<'+1 Post. Ujelly?'>
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
22 Jan 2012 10:38 PM
Uhh, what?
Yes, I understood the question, and mine works exactly as expected in normal Lua, did you even try it?
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
22 Jan 2012 11:19 PM
"@Stravent, he wanted one for Lua, not rbx.lua."
That's exactly what he wrote. Did you look at the code?
Report Abuse
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
22 Jan 2012 11:53 PM
> Explaining why couritines and ROBLOX wait() never work for me.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
23 Jan 2012 12:30 AM
Ah,
"Spawn(function()
print("Hello, World...")
for i = 1, 10 do
wait(1)
print("..."..i)
end
end)"

Saw that and assumed it was rbx.lua, then read the first bit of your code. My bad.

­<'+1 Post. Ujelly?'>
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