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: "wait" function

Previous Thread :: Next Thread 
MinElv is not online. MinElv
Joined: 10 Dec 2012
Total Posts: 32
16 Jan 2013 01:45 PM
roblox use below as wait?

[[

local stf=require'socket';

wait=stf.sleep;

]]
Report Abuse
kholech is not online. kholech
Joined: 18 Dec 2009
Total Posts: 1135
16 Jan 2013 01:49 PM
wait is not a function, and this doesn't look like lua.
Report Abuse
MinElv is not online. MinElv
Joined: 10 Dec 2012
Total Posts: 32
16 Jan 2013 01:51 PM
eh... lua's syntax is flexible if you don't know
Report Abuse
kholech is not online. kholech
Joined: 18 Dec 2009
Total Posts: 1135
16 Jan 2013 01:52 PM
what are you waiting for?
Report Abuse
MinElv is not online. MinElv
Joined: 10 Dec 2012
Total Posts: 32
16 Jan 2013 01:55 PM
[[

stf=require'socket';

wait=function(t)
local now=os.clock();
stf.sleep(t);
return os.clock()-now;
end;

]]

loaoALO
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
16 Jan 2013 01:57 PM
It's not written in Lua code. It probably directly yields and resumes the coroutine.
Report Abuse
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
16 Jan 2013 02:04 PM
Roblox has this ticker called the "RunService" which has an event that fires every frame. The wait function might be built off of that.

r=game:GetService("RunService");
function wait(t)
finishTime = time() + t or 0;
repeat
r.Stepped:wait();
until finishTime >= time();
end

I'm sure it's more advanced than this, but this would work for a low number of scripts. I'll bet it's much more optimised so only one connection to the runservice needs to be made.
Report Abuse
MinElv is not online. MinElv
Joined: 10 Dec 2012
Total Posts: 32
16 Jan 2013 02:10 PM
blobby

print(reunService.Stepped());--always 0.03333333
print(wait(0.033));--something random like socket.sleep(0.033);
Report Abuse
MinElv is not online. MinElv
Joined: 10 Dec 2012
Total Posts: 32
16 Jan 2013 02:43 PM
:3

[[

using=function(t)
for n,v in next,t do
local o=rawget(getfenv(),n);
if(o~=nil)then
print('WARNING:','"'..n..'" cross variable ('..tostring(v)..' & '..tostring(o)..')');
end;
rawset(getfenv(),n,v);
end;
end;

using(coroutine);
using(require'socket');
using(require'socket.http');

-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

count=0;

url='http://www.roblox.com/Forum/ShowPost.aspx?PostID=%d';

ids={87076077;86868836;86868633;86299076;};

repeat
for i=1,#ids do
resume(create(function()
request(url:format(ids[i]));
count=count+1;
print(count);
end));
end;
until sleep(0.1);

]]
Report Abuse
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
16 Jan 2013 03:28 PM
What exactly are you trying to accomplish?
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Jan 2013 03:31 PM
Nah, it's most likely a C-side function binded into the global table. I wrote my own Wait function for LuaJ (Java implementation of Lua, rather than C).

I just had to yield the current thread the script ran on until the time expired.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Jan 2013 03:34 PM
Here's what mine ended up looking like. It became a bit messy only because I decided to wrap each Lua file with a coroutine instead, since not all the Lua files ran on their own thread.

Of course, my method is a bit costly, since it spawns a new true thread alone just for the delayed wait.


    public static void wait(final double t, final LuaThread thread) {
        (new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep((long)t);
                    thread.resume(LuaValue.NIL);
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
Report Abuse
epicfail22 is not online. epicfail22
Joined: 25 Sep 2009
Total Posts: 3739
16 Jan 2013 03:36 PM
Neat. Just one question, what's the use in converting 't' from a double to a long? I know there's a term for this, I forgot it though. I prefer C# now instead of Java.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Jan 2013 03:39 PM
All numbers in Lua are seen as doubles, therefore it's easier to just convert it right to its true type when it's passed to the Java-side wait function there. Then it's converted to a 'long,' since Thread.sleep requires that.

I just noticed too that I didn't make mine a true Java-to-Lua global. But I did loop it in with this bit of Lua code:

    function WaitMillis(tm)
        tm = tonumber(tm)
        tm = (tm and (tm < 0 and 0 or tm) or 0)
        local t = time()
        javaGlobal:wait(tm,thread)
        coroutine.yield(thread)
        return (time()-t)
    end
    
    function Wait(tm)
        tm = tonumber(tm)
        tm = (tm and (tm < 0 and 0 or tm) or 0)
        return WaitMillis(tomillis(tm))
    end
Report Abuse
MinElv is not online. MinElv
Joined: 10 Dec 2012
Total Posts: 32
16 Jan 2013 03:45 PM
you talking to who?
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