time limit for scripts?

For AI and campaign script related discussions and questions
Originway
Trained
Trained
Posts: 412
Joined: 08 Aug 2012, 06:22

time limit for scripts?

Post by Originway »

is there a time limit that kicks in while doing something in a script?
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: time limit for scripts?

Post 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.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Originway
Trained
Trained
Posts: 412
Joined: 08 Aug 2012, 06:22

Re: time limit for scripts?

Post 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?
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: time limit for scripts?

Post 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
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Originway
Trained
Trained
Posts: 412
Joined: 08 Aug 2012, 06:22

Re: time limit for scripts?

Post 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?
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: time limit for scripts?

Post 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.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: time limit for scripts?

Post 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).
Originway
Trained
Trained
Posts: 412
Joined: 08 Aug 2012, 06:22

Re: time limit for scripts?

Post by Originway »

how can we tell when the script is using too much time then?
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: time limit for scripts?

Post 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.
Originway
Trained
Trained
Posts: 412
Joined: 08 Aug 2012, 06:22

Re: time limit for scripts?

Post 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?
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: time limit for scripts?

Post 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).
Originway
Trained
Trained
Posts: 412
Joined: 08 Aug 2012, 06:22

Re: time limit for scripts?

Post 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?
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: time limit for scripts?

Post by aubergine »

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
Originway
Trained
Trained
Posts: 412
Joined: 08 Aug 2012, 06:22

Re: time limit for scripts?

Post by Originway »

aubergine wrote:I'm not on Windows, but would this help? viewtopic.php?f=35&t=10080
thanks for the tip!
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: time limit for scripts?

Post 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.
Post Reply