The question about the delay function in squirrel by the O.P. in thread Help with Generator Function and Delay (http://forum.vc-mp.org/?topic=303.0) is obvious . I'm too looking for such a way that we execute some lines & then for the rest of the resources in that function , we need to produce a time lag .
Although , this could be done by creating a function first & then whatever need to be executed with some time lag have to put in another function . I actually have tried to test this fact on my own about 4-5 months ago :-
function X_print()
{
print(" 1 ");
print(" 2 ");
print(" 3 ");
NewTimer("delay", 5000, 1);
print(" 8 ");
print(" 9 ");
print(" 10 ");
print(" 11 ");
}
function delay()
{
print(" 4 ");
print(" 5 ");
print(" 6 ");
print(" 7 ");
}
function onScriptLoad() X_print();
This will print 1,2,3,8,9,10,11,4,5,6,7 . Actually I was assuming here that the portion of function X_print which comes after Newtimer will execute after delay has finished its run-time . But, results shows that :-
No doubt that newtimer will create a time lag in trigerring the delay function but the X_print function would continue to execute its resources in that time duration . Now , to get the results in desired order, I changed the function as :-
function X_print()
{
print(" 1 ");
print(" 2 ");
print(" 3 ");
NewTimer("delay", 5000, 1);
}
function delay()
{
print(" 4 ");
print(" 5 ");
print(" 6 ");
print(" 7 ");
print(" 8 ");
print(" 9 ");
print(" 10 ");
print(" 11 ");
}
Although it will print our desired result . But , I'm feeling that " Are we relying on a dummy function to create a delay ?? ". Could this be possible that something is executed to certain line & then we use delay() function to seize the activity period in squirrel just like in C++ ? This delay could be written into the core of the server as an inbuilt callback by the developers . Otherwise upto my scope , I aint sure about it to do something with this in squirrel . Who knows maybe I need some clarification .
Are you sure you want that? A delay will cause the whole script to wait, which means events are not being processed, kills not recorded, stats not saved etc. etc.
Quote from: Thijn on Mar 01, 2015, 11:45 AMAre you sure you want that? A delay will cause the whole script to wait, which means events are not being processed, kills not recorded, stats not saved etc. etc.
That's why I told him to look into my healing script at the co-routine to be able to suspend the process and resume it with a timer or whenever he needs it :)
Quote from: Thijn on Mar 01, 2015, 11:45 AMAre you sure you want that? A delay will cause the whole script to wait, which means events are not being processed, kills not recorded, stats not saved etc. etc.
I didn't think about it . Yes , it can have bad consequences as you described . Thanks for clearing things out here .
Quote from: S.L.C on Mar 01, 2015, 11:47 AMthe co-routine to be able to suspend the process and resume it with a timer
Sounds nice . I forget the fact that Squirrel has been made to extend the features it got through C++ . I will check it out .
Meanwhile , I recalled the reason for the output 1,2,3,8,9,10,11,4,5,6,7 . NewTimer will not get executed until Squirrel has done deal with its own resources & thereafter Server will tell the Squirrel Virtual Machine to execute it .