BatchPlay, resetting all global variable

HI Everyone
Stuck in this strange issue from last 2 days. Basic These of my plugin working is as follows, it is taking
images folder and psd folder from user. Then perform certain action on each image for each PSD.

i have made three global variables, which i use in main operations.

let srcPathTokken = [];
let mockupPathTokken = [];
let outToken = {};

the problem is that whenever i run any batch play object like selectAll or any function these above three global variables gets rested. :frowning:

like in following code


srcPathTokken.forEach(async (sImg) => {
		let curDesignImg = sImg;
		for (let index = 0; index < designLyrs.length; index++) {
			let curDesignLyr = designLyrs[index]; // till this point every thing is fine
			selectLayer(curDesignLyr._id);  // when this function is called objects gets reset
			await browseAndSetDisplayFile(curDesignImg, false);

			let outFold_mockup;
			try {
				outFold_mockup = await outToken.getEntry(fName)
			} catch (e) {
				outFold_mockup = await outToken.createFolder(fName);

			newFileName = "whateverName.jpg";
			var myFile = await outFold_mockup.createFile(newFileName, { overwrite: true });
			let jpegOptions = {
				quality: 100,
				embedColorProfile: true
			app.activeDocument.saveAs.jpg(myFile, jpegOptions, true);

		} // desired layers loop ends
	}) // img loop end

in the above code once i call selectLayer function , its bactchplay runs and it reset the objects. i tried to apply other batch play but same result with all functions. can someone please guide.

BTW this is my batch play function and it is running in othe rplugins correctly

async function selectLayer(lyrId){
 await core.executeAsModal(async () => {
         return await psAction.batchPlay([
               _obj: "select",
               _target: [
                     _ref: "layer",
                     _id: parseInt(lyrId)
               makeVisible: false,
               // layerID: [
               //    lyrId
               // ],
               _options: {
                  dialogOptions: "dontDisplay"
         ], {})
      }, { "commandName": "Select a layer by name" })