Page 1 of 2

time limit for scripts?

Posted: 09 Nov 2012, 00:29
by Originway
is there a time limit that kicks in while doing something in a script?

Re: time limit for scripts?

Posted: 09 Nov 2012, 00:39
by aubergine
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.

Re: time limit for scripts?

Posted: 10 Nov 2012, 02:31
by Originway
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?

Posted: 10 Nov 2012, 02:53
by aubergine
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

Re: time limit for scripts?

Posted: 10 Nov 2012, 07:34
by Originway
we saw this in the code

Code: Select all

// the maximum number of instructions to execute before assuming
// an infinite loop
#define INTERP_MAXINSTRUCTIONS		300000
#define MAX_FUNC_CALLS 300
is there something like that for the new script?

Re: time limit for scripts?

Posted: 10 Nov 2012, 08:00
by aubergine
If your code is doing that many instructions or function calls in a single event, then something is obviously very wrong with it lol.

Re: time limit for scripts?

Posted: 10 Nov 2012, 13:29
by Per
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?

Posted: 15 Nov 2012, 20:58
by Originway
how can we tell when the script is using too much time then?

Re: time limit for scripts?

Posted: 15 Nov 2012, 22:04
by Per
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?

Posted: 15 Nov 2012, 22:28
by Originway
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.
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.
where does this warning appear on the screen?

Re: time limit for scripts?

Posted: 15 Nov 2012, 22:40
by Per
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).

Re: time limit for scripts?

Posted: 15 Nov 2012, 22:49
by Originway
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).
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?

Re: time limit for scripts?

Posted: 15 Nov 2012, 23:00
by aubergine
I'm not on Windows, but would this help? viewtopic.php?f=35&t=10080

Re: time limit for scripts?

Posted: 15 Nov 2012, 23:13
by Originway
aubergine wrote:I'm not on Windows, but would this help? viewtopic.php?f=35&t=10080
thanks for the tip!

Re: time limit for scripts?

Posted: 15 Nov 2012, 23:35
by Per
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?
Yes, those builds should work.

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.