time limit for scripts?
time limit for scripts?
is there a time limit that kicks in while doing something in a script?
Re: time limit for scripts?
No - scripts can run as long as they want. However, if they run too long, you'll cause game lag because WZ freezes while the script is doing something.
Sounds like you're investigating the same thing as me: viewtopic.php?f=35&t=10193
I'm developing an API (well, it's finished, just tidying it up before releasing) that can run code across multiple "processing slots" (for want of better description). Means that if you have a long running task, you can get it to do some number crunching, then pause to let WZ do some stuff, and then it will automatically resume a bit later.
Part of my API defines a global property called "timeRemaining" which lets you know how much time you've spent number crunching in the current processing slot.
The issue I'm having is that events are fired when they occur, rather than being bunched up and fired at regular intervals, so a processing slot could be a single millisecond of gameTime, which kinda throws a spanner in the works of my current implementation, but not an insurmountable one.
Sounds like you're investigating the same thing as me: viewtopic.php?f=35&t=10193
I'm developing an API (well, it's finished, just tidying it up before releasing) that can run code across multiple "processing slots" (for want of better description). Means that if you have a long running task, you can get it to do some number crunching, then pause to let WZ do some stuff, and then it will automatically resume a bit later.
Part of my API defines a global property called "timeRemaining" which lets you know how much time you've spent number crunching in the current processing slot.
The issue I'm having is that events are fired when they occur, rather than being bunched up and fired at regular intervals, so a processing slot could be a single millisecond of gameTime, which kinda throws a spanner in the works of my current implementation, but not an insurmountable one.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: time limit for scripts?
my friend said the old script system has a maximum amount of time the script would be active and I guess this isn't true for the new script system?
Re: time limit for scripts?
When you say "active", do you mean actually running code or just idling?
In the JS API code is only run in 2 scenarios:
1. When scripts instantiate (eg. at the start of a game) they run some code. If they went in to some sort of never-ending loop, the game would never actually start because it freezes while the JS code is processing.
2. When events are triggered, the handlers in your script are invoked and do some processing. While your handler is doing some processing, WZ will be frozen. When the processing finishes, control is handed back to WZ and the game continues until the next event is triggered.
But, while your code isn't running, the JS environment it's running in just sits there doing nothing.
If code in your script takes a long time to process, eg. iterating through a massive list of all game objects in some nested / recursive manner, then WZ will sit and wait patiently until it's finished before doing anything else.
Does that answer your question?
BTW, I recently did some digging in to various initialisation sequences in the WZ environment (just from observations so might be errors in this): https://warzone.atlassian.net/wiki/disp ... +Sequences
In the JS API code is only run in 2 scenarios:
1. When scripts instantiate (eg. at the start of a game) they run some code. If they went in to some sort of never-ending loop, the game would never actually start because it freezes while the JS code is processing.
2. When events are triggered, the handlers in your script are invoked and do some processing. While your handler is doing some processing, WZ will be frozen. When the processing finishes, control is handed back to WZ and the game continues until the next event is triggered.
But, while your code isn't running, the JS environment it's running in just sits there doing nothing.
If code in your script takes a long time to process, eg. iterating through a massive list of all game objects in some nested / recursive manner, then WZ will sit and wait patiently until it's finished before doing anything else.
Does that answer your question?
BTW, I recently did some digging in to various initialisation sequences in the WZ environment (just from observations so might be errors in this): https://warzone.atlassian.net/wiki/disp ... +Sequences
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: time limit for scripts?
we saw this in the code is there something like that for the new script?
Code: Select all
// the maximum number of instructions to execute before assuming
// an infinite loop
#define INTERP_MAXINSTRUCTIONS 300000
#define MAX_FUNC_CALLS 300
Re: time limit for scripts?
If your code is doing that many instructions or function calls in a single event, then something is obviously very wrong with it lol.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: time limit for scripts?
IIRC, wzscript would abort loops after a number of iterations. There is a way to limit javascript execution time (by milliseconds), but I have not turned that on (yet).
Re: time limit for scripts?
how can we tell when the script is using too much time then?
Re: time limit for scripts?
You mean as a script developer? There is a warning that will be emitted if any script call takes too long. I can turn on the javascript execution time limiter, too, but I'm not sure it is worth doing at the moment.
Re: time limit for scripts?
yes, a buddy of mine is a javascript developer and we are trying to make a micro-AI that can do more advanced abilities but the math for this is slowing things down too much it seems.Per wrote:You mean as a script developer? There is a warning that will be emitted if any script call takes too long. I can turn on the javascript execution time limiter, too, but I'm not sure it is worth doing at the moment.
where does this warning appear on the screen?
Re: time limit for scripts?
Warning is posted to the console if debug logging for scripts is turned on and a script call takes more than 50 ms. To turn on debug logging for scripts, run warzone as ' warzone2100 --debug=script'. This will generate a lot of extra debug data. I should probably put most of this info somewhere more accessible, though.
Note that this works only for 3.2 (master).
Note that this works only for 3.2 (master).
Re: time limit for scripts?
any version from http://buildbot.wz2100.net/files/master/windows will work?Per wrote:Warning is posted to the console if debug logging for scripts is turned on and a script call takes more than 50 ms. To turn on debug logging for scripts, run warzone as ' warzone2100 --debug=script'. This will generate a lot of extra debug data. I should probably put most of this info somewhere more accessible, though.
Note that this works only for 3.2 (master).
on windows, it don't show a console, so is there a way to show that data on the screen?
Re: time limit for scripts?
I'm not on Windows, but would this help? viewtopic.php?f=35&t=10080
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
-- https://warzone.atlassian.net/wiki/display/GO
Re: time limit for scripts?
thanks for the tip!aubergine wrote:I'm not on Windows, but would this help? viewtopic.php?f=35&t=10080
Re: time limit for scripts?
Yes, those builds should work.Originway wrote:any version from http://buildbot.wz2100.net/files/master/windows will work?
on windows, it don't show a console, so is there a way to show that data on the screen?
Do you really want that data on the screen? I am thinking perhaps a separate debug output file for script would be more appropriate? So anything you put in debug() calls go into that file.