# Draw Game Objects from outside create function

**URL:** <https://phaser.discourse.group/t/draw-game-objects-from-outside-create-function/12203>\
**Category:** Phaser 3\
**Created:** [August 22, 2022, 6:34pm UTC](https://phaser.discourse.group/t/draw-game-objects-from-outside-create-function/12203 "2022-08-22T18:34:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FlashDroid](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/flashdroid/32/3137_2.png) [@FlashDroid](https://phaser.discourse.group/u/FlashDroid)\
**Post date:** [August 22, 2022, 6:34pm UTC](https://phaser.discourse.group/t/draw-game-objects-from-outside-create-function/12203/1 "2022-08-22T18:34:57Z")

</div>

From outside create function does anyone know how to draw lines or another game Objects? I ask this because the console log returns an error when i create some lines outside create function.

Error In console log:

> Uncaught TypeError: Cannot read properties of undefined (reading ‘line’).

Can you help me?

```javascript
var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

var l1

function preload ()
{ }

function create ()
{
    drawLines ();
}

function drawLines ()
{
    l1 = this.add.line(0,0, 50,50, 100, 100, 0x0000ff, 0.5).setOrigin(0);
}

```

---

<div class="post-metadata">

**Author:** ![nish\_mishra](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@nish\_mishra](https://phaser.discourse.group/u/nish_mishra)\
**Post date:** [August 23, 2022, 7:48am UTC](https://phaser.discourse.group/t/draw-game-objects-from-outside-create-function/12203/2 "2022-08-23T07:48:33Z")

</div>

can you share a fiddle / SS of the error for the same, code itself looks fine.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 23, 2022, 3:36pm UTC](https://phaser.discourse.group/t/draw-game-objects-from-outside-create-function/12203/3 "2022-08-23T15:36:22Z")

</div>

You need to set the calling context (this).

```javascript
function create ()
{
    drawLines.call(this);
}

function drawLines ()
{
    l1 = this.add.line(0,0, 50,50, 100, 100, 0x0000ff, 0.5).setOrigin(0);
}

```
