# How to pass arguments to new sketch in instance mode

**URL:** <https://discourse.processing.org/t/how-to-pass-arguments-to-new-sketch-in-instance-mode/11453>\
**Category:** Coding Questions\
**Created:** [May 21, 2019, 7:04am UTC](https://discourse.processing.org/t/how-to-pass-arguments-to-new-sketch-in-instance-mode/11453 "2019-05-21T07:04:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimR](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@TimR](https://discourse.processing.org/u/TimR)\
**Post date:** [May 21, 2019, 7:04am UTC](https://discourse.processing.org/t/how-to-pass-arguments-to-new-sketch-in-instance-mode/11453/1 "2019-05-21T07:04:54Z")

</div>

Hey all,

Is there a way to pass an arguments array/object to a new sketch in instance mode?  
I would like to pass settings to the new sketch, like information on who is it’s parent element. But this could also be used to send other settings like colors or dimensions of stuff to be drawn.

This was my first approach/guess

```auto
var p5Back = function( sketch, args ) {

	let parentDivId = args.parentId;
	
	console.log( parentDivId );
}

let sketch_01 = new p5( p5Back, ‘sketch_01’, { parentId: ‘sketch_01’ } );
let sketch_02 = new p5( p5Back, ‘sketch_02’, { parentId: ‘sketch_02’ } );

```

But this prints `TypeError: args is undefined` in the console.

Is there a way to pass arguments to the new sketch?

---

<div class="post-metadata">

**Author:** ![TimR](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@TimR](https://discourse.processing.org/u/TimR)\
**Post date:** [May 21, 2019, 7:50am UTC](https://discourse.processing.org/t/how-to-pass-arguments-to-new-sketch-in-instance-mode/11453/2 "2019-05-21T07:50:27Z")

</div>

I think I might already have found a solution for this:

```auto
function createNewSketch( args ){

    let p5Back = function( sketch ) {

        sketch.setup = function() {

            sketch.createCanvas( args.width, args.height);

        }

    };

    return new p5( p5Back, args.parentId );
}

let sketch_01 = createNewSketch( { parentId: 'sketch_01', width: 200, height: 50 } );

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [May 22, 2019, 6:49am UTC](https://discourse.processing.org/t/how-to-pass-arguments-to-new-sketch-in-instance-mode/11453/3 "2019-05-22T06:49:27Z")

</div>

This seems to be relevant: [https://stackoverflow.com/questions/46290952/passing-in-extra-argument-to-new-p5-instance](https://stackoverflow.com/questions/46290952/passing-in-extra-argument-to-new-p5-instance)

Kf
