How To Sleep

Started by vcmptr, May 25, 2015, 06:51 AM

Previous topic - Next topic

vcmptr

I need sleep like PHP sleep function. How can I do with Squirrel?
My English is not good.

Murdock

I don't think Squirrel has a function like that, but you can achieve the same by using timers or coroutines

Thijn

I would like to add that the sleep function in PHP actually halts everything. Doing this in Squirrel will mean your server will stop responding to events and whatnot. Which causes a massive lagspike.

Using timers is the way to go if you would like to get a similar feature.

vcmptr

Quote from: Murdock on May 25, 2015, 11:16 AMI don't think Squirrel has a function like that, but you can achieve the same by using timers or coroutines
Quote from: Thijn on May 25, 2015, 03:18 PMI would like to add that the sleep function in PHP actually halts everything. Doing this in Squirrel will mean your server will stop responding to events and whatnot. Which causes a massive lagspike.

Using timers is the way to go if you would like to get a similar feature.
Thanks. :) I will use timers.
My English is not good.

.

There's a reason that scripting languages with interests towards games don't have the sleep function. Because I'm not sure how you think the sleep function works but it basically means halt my program here for this amount of time. And then your server would simply stop for that amount of time. I'm sure you've seen some server having glitches from time to time. Especially when they have a poor database implementation with SQLite. The server simply stops for a moment until the data is fetched or inserted into the database. Same thing happens with the sleep function. I'm sure you remember the issue with screenshots freezing the game. That's another effect that demonstrates how the sleep function would affect the game.

It would take only a few seconds to expose the sleep function from C/C++ to Squirrel. But that wouldn't help anyone.
.

vcmptr

Quote from: S.L.C on May 25, 2015, 03:43 PMThere's a reason that scripting languages with interests towards games don't have the sleep function. Because I'm not sure how you think the sleep function works but it basically means halt my program here for this amount of time. And then your server would simply stop for that amount of time. I'm sure you've seen some server having glitches from time to time. Especially when they have a poor database implementation with SQLite. The server simply stops for a moment until the data is fetched or inserted into the database. Same thing happens with the sleep function. I'm sure you remember the issue with screenshots freezing the game. That's another effect that demonstrates how the sleep function would affect the game.

It would take only a few seconds to expose the sleep function from C/C++ to Squirrel. But that wouldn't help anyone.
Thanks for explain. :) I thought to generate random numbers.
My English is not good.

.

#6
Quote from: vcmptr on May 25, 2015, 04:24 PM... I thought to generate random numbers.

Just use this in your onServerStart callback:
function onServerStart()
{
srand( (GetTickCount() % time()) / 3 );


print( rand() );
print( rand() );
print( rand() );
print( rand() );
print( rand() );
print( rand() );
print( rand() );
print( rand() );
}

And then use random() in your code as you would normally do.
.

Stormeus

First person to implement Mersenne Twister random numbers in Squirrel gets a cookie.

.

Quote from: stormeus on May 25, 2015, 05:01 PMFirst person to implement Mersenne-Twister random numbers in Squirrel gets a cookie.

You know I can do that in just a few seconds. Although, is C++11 allowed? :P
.

Stormeus

Quote from: S.L.C on May 25, 2015, 05:02 PM
Quote from: stormeus on May 25, 2015, 05:01 PMFirst person to implement Mersenne-Twister random numbers in Squirrel gets a cookie.

You know I can do that in just a few seconds. Although, is C++11 allowed? :P

That's no fun. Pure Squirrel.

.

Quote from: stormeus on May 25, 2015, 05:10 PMThat's no fun. Pure Squirrel.

As much fun as that sounds like I don't really plan on wasting time with something that's never going to be used :D
.