# BatchPlay, resetting all global variable

**URL:** <https://forums.creativeclouddeveloper.com/t/batchplay-resetting-all-global-variable/6212>\
**Category:** UXP Plugin API\
**Tags:** javascript\
**Created:** [April 23, 2023, 3:31pm UTC](https://forums.creativeclouddeveloper.com/t/batchplay-resetting-all-global-variable/6212 "2023-04-23T15:31:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsehtak](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hsehtak](https://forums.creativeclouddeveloper.com/u/hsehtak)\
**Post date:** [April 23, 2023, 3:31pm UTC](https://forums.creativeclouddeveloper.com/t/batchplay-resetting-all-global-variable/6212/1 "2023-04-23T15:31:48Z")

</div>

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.

```auto
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. ☹

like in following code

> Blockquote

```
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);
				console.log("foldCreated");
			}

			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

```auto
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" })
}

```
