# When to use this.data.set()?

**URL:** <https://phaser.discourse.group/t/when-to-use-this-data-set/7424>\
**Category:** Phaser 3\
**Created:** [September 14, 2020, 1:37pm UTC](https://phaser.discourse.group/t/when-to-use-this-data-set/7424 "2020-09-14T13:37:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickChowHK](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nickchowhk/32/2377_2.png) [@NickChowHK](https://phaser.discourse.group/u/NickChowHK)\
**Post date:** [September 14, 2020, 1:37pm UTC](https://phaser.discourse.group/t/when-to-use-this-data-set/7424/1 "2020-09-14T13:37:18Z")

</div>

function create(){  
this.GameOver = false;  
this.data.set(‘GameOver’, false);  
}

I am wondering when to assign data to “this.data” rather than assign it to “this” directly.  
Can someone tell me the concept? Many Thanks.

---

<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:** [September 14, 2020, 4:14pm UTC](https://phaser.discourse.group/t/when-to-use-this-data-set/7424/2 "2020-09-14T16:14:45Z")

</div>

If you just need “a variable to use in this scene”, use `this.GameOver`.

[this.data](https://photonstorm.github.io/phaser3-docs/Phaser.Data.DataManager.html) is a more structured interface.

---

<div class="post-metadata">

**Author:** ![NickChowHK](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nickchowhk/32/2377_2.png) [@NickChowHK](https://phaser.discourse.group/u/NickChowHK)\
**Post date:** [September 15, 2020, 1:02am UTC](https://phaser.discourse.group/t/when-to-use-this-data-set/7424/3 "2020-09-15T01:02:41Z")

</div>

Thanks for your reply. The data manager state that:

“The parent must either extend EventEmitter, or have a property called `events` that is an instance of it”

Does it mean when the data change, the data change event could be emitted?

Is it better to trigger a “data” event rather than put GameOver variable to update()

---

<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:** [September 15, 2020, 8:37pm UTC](https://phaser.discourse.group/t/when-to-use-this-data-set/7424/4 "2020-09-15T20:37:14Z")

</div>

Yes, the scene’s data manager (`this.data`) triggers events from the scene’s event emitter (`this.events`).

You can [use scene events](http://labs.phaser.io/view.html?src=src/events/emit%20scene%20event.js "emit scene event") without the scene data manager. For example, you would just emit a _gameover_ event, no data involved:

```javascript
this.events.on('gameover', function () {/*…*/});
// …
this.events.emit('gameover');

```

---

<div class="post-metadata">

**Author:** ![NickChowHK](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nickchowhk/32/2377_2.png) [@NickChowHK](https://phaser.discourse.group/u/NickChowHK)\
**Post date:** [September 16, 2020, 8:47am UTC](https://phaser.discourse.group/t/when-to-use-this-data-set/7424/5 "2020-09-16T08:47:49Z")

</div>

Thanks, this can be a solution to my question already.
