# Explanation of the "self"argument for dummies

**URL:** <https://forum.defold.com/t/explanation-of-the-self-argument-for-dummies/44691>\
**Category:** Questions\
**Created:** [February 26, 2019, 7:45pm UTC](https://forum.defold.com/t/explanation-of-the-self-argument-for-dummies/44691 "2019-02-26T19:45:20Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ross.grams](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/r/cab0a1/32.png) [@ross.grams](https://forum.defold.com/u/ross.grams)\
**Post date:** [February 26, 2019, 8:00pm UTC](https://forum.defold.com/t/explanation-of-the-self-argument-for-dummies/44691/2 "2019-02-26T20:00:46Z")

</div>

For all practical purposes, it is a table that you can use to store properties that are specific to one, single object (since you can have many different copies of the same object).

If you define a `local` variable at the top of your script, that variable will be shared by all instance of the script. If one of them changes it, it will be different for all. But if you put something in `self`, it will only be changed for, and only be accessible to, that one instance.

For example if you have a bullet object with a script on it. When you fire a shotgun, you will spawn a bunch of these bullets. If you do this:

```lua
local speed = 500

function init(self)
	speed = math.random(300, 600)
end

function update(self, dt)
	local p = go.get_position()
	p.x = p.x + speed * dt
	go.set_position(p)
end

```

You randomize the value of `speed` when each bullet is spawned, but since you define it as a `local` variable like that, it is shared between all of them, and they will all use the same value (as set by the _last_ bullet to spawn).

If instead you do this:

```lua
function init(self)
	self.speed = math.random(300, 600)
end

function update(self, dt)
	local p = go.get_position()
	p.x = p.x + self.speed * dt
	go.set_position(p)
end

```

Then each individual bullet will have its own random speed that it will use. It won’t interfere with any other bullets.

---

_[View the full topic](https://forum.defold.com/t/explanation-of-the-self-argument-for-dummies/44691)._
