Cloaking mission AND JS

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Cloaking mission AND JS

Post by Eric Walch »

The JS example of the cloaking device mission has a didactic bug. It transfers the value of a mission variable to a local variable to do al the calculations with. At the end the value of the local variable it put back into the mission variable.

For readers this complex handling leads to the conclusion JS can't calculate with missionVariables. At least it did with me and I didn't even check if it did work until yesterday. With my first UPS translation I just copied this complex structure. Probably it was necessary with 1.69 JS but not anymore with 1.70 JS. Technically the code may do a lot of work to let the missionVarriables behave like normal variables. But when it works, show it in the internal script examples! Now I only saw that "var" in the 1.69 script was changed into "let" for the 1.70 script.


Current code

Code: Select all

    // ...then we count of jumps...
    let cloakCounter = missionVariables.cloakcounter;
    if (cloakCounter == null)  cloakCounter = 1;
    else  cloakCounter++;
    missionVariables.cloakcounter = cloakCounter;
    
    // ...until we reach six or more.
    if (cloakCounter > 6 && system.countShipsWithRole("asp-cloaked") == 0)

New code

Code: Select all

    // ...then we count of jumps...
    if (!missionVariables.cloakcounter)  missionVariables.cloakcounter = 1;
    else  missionVariables.cloakcounter++;
    
    // ...until we reach six or more.
    if (missionVariables.cloakcounter > 6 && system.countShipsWithRole("asp-cloaked") == 0)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

This was probably premature optimization on my part – access to mission variables is significantly more expensive than local variables, but not to the extent that it’ll matter in a shipWillExitWitchspace function. For more complex calculations, a local variable can also be more legible. But yes, you’re right.
User avatar
Captain Hesperus
Grand High Clock-Tower Poobah
Grand High Clock-Tower Poobah
Posts: 2310
Joined: Tue Sep 19, 2006 1:10 pm
Location: Anywhere I can sell Trumbles.....

Post by Captain Hesperus »

Ahruman wrote:
This was probably premature optimization on my part
Don't worry, Ahruman, it happens to all of us at one time or another. :wink: If it continues, I can get you some little pills to help.
:D

Captain Hesperus
The truth, revealed!!
Image
Post Reply