Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: vcmptr on May 25, 2015, 06:51 AM

Title: How To Sleep
Post by: vcmptr on May 25, 2015, 06:51 AM
I need sleep like PHP sleep function (http://php.net/manual/en/function.sleep.php). How can I do with Squirrel?
Title: Re: How To Sleep
Post by: Murdock on May 25, 2015, 11:16 AM
I don't think Squirrel has a function like that, but you can achieve the same by using timers or coroutines
Title: Re: How To Sleep
Post by: Thijn on May 25, 2015, 03:18 PM
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.
Title: Re: How To Sleep
Post by: vcmptr on May 25, 2015, 03:24 PM
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.
Title: Re: How To Sleep
Post by: . on May 25, 2015, 03:43 PM
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.
Title: Re: How To Sleep
Post by: vcmptr on May 25, 2015, 04:24 PM
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.
Title: Re: How To Sleep
Post by: . on May 25, 2015, 04:34 PM
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.
Title: Re: How To Sleep
Post by: Stormeus on May 25, 2015, 05:01 PM
First person to implement Mersenne Twister random numbers in Squirrel gets a cookie.
Title: Re: How To Sleep
Post by: . 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
Title: Re: How To Sleep
Post by: Stormeus on May 25, 2015, 05:10 PM
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.
Title: Re: How To Sleep
Post by: . on May 25, 2015, 06:05 PM
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