Page 1 of 1

use of scriptTimer_number

Posted: Thu Dec 13, 2007 12:28 pm
by Commander McLane
While I am playing Deposed I am working on this OXP, making it mission-clash-proof. As soon as I'm finished I'm going to upload it to the wiki. (Will be v.1.3.)

Examining the script I noticed that it uses the scriptTimer-method, which in the Wiki is marked as deprecated and should not be used anymore. It's only in two places, for the purpose of replacing killed enemies after a certain while into a battle. The code looks like this:

Code: Select all

        {
            conditions = (
                "galaxy_number equal 3", 
                "mission_deposed equal PART1_1", 
                "status_string equal STATUS_IN_FLIGHT", 
                "scriptTimer_number lessthan 60"
            ); 
            do = (
                "checkForShips: bien", 
                {
                    conditions = ("shipsFound_number lessthan 5", "d100_number lessthan 30"); 
                    do = ("addSystemShips: bien 1 0.35"); 
                }
            ); 
        }, 
I guess it probably never worked like intended, because there is no resetScriptTimer anywhere. My question to the codemonkeys: Is the script timer as a method supported at all anymore? Was it in 1.65? And in the current development versions?

I probably would go for deleting it from the code anyway, but I'd like to know whether it did anything in any of the Oolite versions currently in use.

Posted: Thu Dec 13, 2007 12:37 pm
by JensAyton
That appears to be copy&pasted from the built-in oolite-thargoid-plans, which also doesn’t call resetScriptTimer.

Looking through the code, it appears that the “script timer” in question is the timer used to decide when to fire the “tickle” event (which runs legacy scripts). It is also used, of all places, in the menu-handling code to throttle key repeat for the up and down arrow keys.

As far as I can see, it’s never reset implicitly except when resetting the player, i.e. when starting a new game, loading, or resetting after death. So those conditions will only be true shortly after loading a game. This probably hasn’t changed since 1.65.

In summary: don’t use scriptTimer_number. :-)

Posted: Thu Dec 13, 2007 8:05 pm
by Eric Walch
Ahruman wrote:
As far as I can see, it’s never reset implicitly except when resetting the player, i.e. when starting a new game, loading, or resetting after death. So those conditions will only be true shortly after loading a game. This probably hasn’t changed since 1.65.
When I started programming Oolite I used it to detect if Oolite had just started up. I use it in my MOP-testing.OXP for that purpose. (Now I would have programmed that in an other way).

But McLane is right. I also noticed that line in deposed and concluded that it is unlikely that those conditions are ever met. (I can not see a reason why it only should work shortly after startup of Oolite and not after launching) But it could be that the author had an other OXP on his computer that always did reset the timer on launch so he didn't notice.
You can't remove the timer as it than always ends up with adding 5 ships.

Posted: Fri Dec 14, 2007 11:02 am
by Commander McLane
Eric Walch wrote:
You can't remove the timer as it than always ends up with adding 5 ships.
Which would give the nice effect of an ongoing battle, as in the context of the script it's opponents of the player who are added. So, whenever you kill one of them, with the next tickle another one jumps in again. :twisted:

And well, you would finally be able to get rid of them by simply moving towards the planet, because they are always spawned at the same point. So sooner or later you would be out of their scanner range and they wouldn't harm you anymore.

So I think I will remove the timer here. :wink:

Posted: Mon Dec 31, 2007 1:12 pm
by Eric Walch
Ahruman wrote:
As far as I can see, it’s never reset implicitly except when resetting the player, i.e. when starting a new game, loading, or resetting after death. So those conditions will only be true shortly after loading a game. This probably hasn’t changed since 1.65.
It is in the PlayerEntity.m file (version 1.70 but probably also the earlier versions). I just stumbled over it looking for something else.

Code: Select all

	if (status == STATUS_EXITING_WITCHSPACE)
	{
		if ([UNIVERSE breakPatternOver])
		{
			// time to check the script!
			[self checkScript];
			// next check in 10s
			[self resetScriptTimer];	// reset the in-system timer
breakPatternOver is the end of the tunnel effect. Then it first checks the script and than resets the timer. So the first scriptTimer_number < 60 will be seen after 10 seconds after the tunnel effect.

The scriptTimer_number is reset after a witchspace jump. Script is running every 10 seconds. So a check of scriptTimer_number lessthan 60 causes this condition to happen about 5 times after a jump.

What happens in thargoid plans is that it adds 2 thargoids after a jump and than 5 times tries to add a thargoid with a 50% change but with a maximum of 5 ships total.

A very complicated way of adding a random number of ships at the witch-space point between 0 and 3 ships.

Deposed copies that method and will try about 5 times to add a ship with 20% change after a jump. On average it adds just one ship. Maybe he therefor duplicated this routine in his script.