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: the 'wait' function

Previous Thread :: Next Thread 
CrazyJoe is not online. CrazyJoe
Joined: 08 Nov 2007
Total Posts: 3458
03 Sep 2011 08:55 PM
I've been working with lua outside ROBLOX for a good three or so years now, and it always bugged me how 'wait' wasn't a pre-programmed function.

It took me until now to bother trying to implement it myself.

function wait(t)

s = os.date("*t").sec
sd = s + t

repeat
until (os.date("*t").sec == sd)
end

--test it out

print("start")
for i = 1, 10 do
print("Repetition: " .. i)
print("Time: " .. os.date("*t").sec)
wait(1)
end
print("end")

However, this breaks if 'sd' exceeds 60: in other words, it'll stop working if the minute changes, since it operates on calculating the seconds. I've tried to add something to make it bypass the minutes for high numbers of t, but it's never worked.

Can someone help me with doing this?
Report Abuse
piemario is not online. piemario
Joined: 17 Jul 2009
Total Posts: 1379
03 Sep 2011 08:57 PM
im sorry im not aware of any programs outside of roblox that use Lua, i know there are alot because if there werent it wouldnt be in Notepad ++ :D
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
03 Sep 2011 08:58 PM
Pie, ScITE

­<'+1 Post. Ujelly?'> IT'S A PEAR http://www.roblox.com/Pear-Hat-item?id=60907280
Report Abuse
CrazyJoe is not online. CrazyJoe
Joined: 08 Nov 2007
Total Posts: 3458
03 Sep 2011 09:00 PM
I downloaded lua 5.2 and an editor for it (nate890's right - SciTe: Scintilla Text Editor) and I use the lExecutor program to test out the program.

If you try to run my script in ROBLOX, of course it will always work: the 'wait' function is already incorporated in ROBLOX.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:05 PM
well that's easy, you'll just have to add all the values together

s = 0;
time=os.date("*t");
s=s+time.sec;
s=s+time.min*60;
s=s+time.hour*60*60;
s=s+time.day*60*60*24;
sd = s + t
Report Abuse
CrazyJoe is not online. CrazyJoe
Joined: 08 Nov 2007
Total Posts: 3458
03 Sep 2011 09:07 PM
@SDuke524: That actually didn't work at all. Thanks for trying, but it didn't get past the first repetition.

We should just ask the guys on the ROBLOX crew that programmed it in the first place, lol.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:11 PM
Well they used coroutine.yield() I know that, but just check over my math and that's how it would be done. I don't actually use lua outside of roblox, instead I just use web programming languages but if there's an easier way to get the UNIX time then use it. I think it was

os.date("!")

then just use that instead with your normal script.
Report Abuse
piemario is not online. piemario
Joined: 17 Jul 2009
Total Posts: 1379
03 Sep 2011 09:13 PM
oh dang i forgot how to do stuff like this. Curse you summer vacation. i think it was something like this:

U = ones(or seconds in this case)
T = tens(minutes)
H = hundreds(hours)

if U >= 60 then
T = T + 1
U = 0
end
if T >= 60 then
H = H + 1
end

--then when u get to doing the actual time it would be

wait((H * 3600) + (T * 60) + (U))


not sure if this helped. i hope it does though
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
03 Sep 2011 09:17 PM
function wait(s)
   local t = os.time() + s
   repeat wait(1) until os.time() == t
end

Maybe?
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
03 Sep 2011 09:18 PM
mlly zylev nzpv ufm lu srn

wut?

­<'+1 Post. Ujelly?'> IT'S A PEAR http://www.roblox.com/Pear-Hat-item?id=60907280
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
03 Sep 2011 09:20 PM
*Facepalm* I just failed epicly.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:20 PM
"repeat wait(1) until os.time() == t"

give me my hats back.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:21 PM
Mll, HkvxgifnD rh xllo W:
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:21 PM
function wait(t)

s = os.date("!")
sd = s + t

repeat
until (os.date("!") == sd)
end

--test it out

print("start")
for i = 1, 10 do
print("Repetition: " .. i)
print("Time: " .. os.date("*t").sec)
wait(1)
end
print("end")
Report Abuse
CrazyJoe is not online. CrazyJoe
Joined: 08 Nov 2007
Total Posts: 3458
03 Sep 2011 09:23 PM
@SDuke524: That just returned the error:

attempt to perform arithmetic on global 's' (a string value)
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:24 PM
s = tonumber(os.date("!"))


sorry
Report Abuse
CrazyJoe is not online. CrazyJoe
Joined: 08 Nov 2007
Total Posts: 3458
03 Sep 2011 09:25 PM
@SDuke524: That just returned the same error. Strange.
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:26 PM
do

print(os.date("!"))

and tell me what it returns
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
03 Sep 2011 09:28 PM
Gszg nzb yv gifv. yfg sv nzb yv z glk hvxivg mlly :l. Gsrmp zylfg rg

­<'+1 Post. Ujelly?'> IT'S A PEAR http://www.roblox.com/Pear-Hat-item?id=60907280
Report Abuse
CrazyJoe is not online. CrazyJoe
Joined: 08 Nov 2007
Total Posts: 3458
03 Sep 2011 09:30 PM
@SDuke524:

The first time, it returned:

'end' expected (to close 'do' at line 67) near 'eof'

and when I added an end to it, it didn't return anything but still executed.


I also tried doing the key-value line for printing tables, but it's not a table either.

for k, v in pairs(os.date("!")) do print(k, v) end

bad argument #1 to 'pairs' (table expected, got string)
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:31 PM
Ml, hkvx'h vkrxzo
Report Abuse
SDuke524 is not online. SDuke524
Joined: 29 Jul 2008
Total Posts: 6267
03 Sep 2011 09:33 PM
strange, it should return the unix time. I guess you're stuck with fixing my math on the first thingy.
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
03 Sep 2011 09:36 PM
Y U NO os.time() ?!
Report Abuse
CrazyJoe is not online. CrazyJoe
Joined: 08 Nov 2007
Total Posts: 3458
03 Sep 2011 09:39 PM
@Spectrumw: os.time() by itself is a table. You need to specify which terms you're working with for anything to work.
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
03 Sep 2011 09:40 PM
print(type(os.time()))
>number

O:
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