# Lives on enemys

**URL:** <https://forum.makecode.com/t/lives-on-enemys/1418>\
**Category:** Help\
**Created:** [March 15, 2020, 8:48pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418 "2020-03-15T20:48:20Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![codebott578](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/codebott578/32/690_2.png) [@codebott578](https://forum.makecode.com/u/codebott578)\
**Post date:** [March 15, 2020, 8:48pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/1 "2020-03-15T20:48:20Z")

</div>

i was wondering, can you add lives to enemy’s in the block coding?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [March 16, 2020, 9:05pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/2 "2020-03-16T21:05:13Z")

</div>

Unfortunately, this is pretty difficult to do in blocks. The hack I usually use is the z-index; you can set the z-index of the sprite to the max number of lives (i.e. 10) and then decrement it whenever the enemy is hit. Then when the z is 0, you destroy the sprite.

If you do that you’ll probably need to set the z-index of the player (and other sprites) to something higher than 10. That way they’ll still be displayed above the sprite.

Here is information on the z-index: [https://arcade.makecode.com/reference/sprites/sprite/z](https://arcade.makecode.com/reference/sprites/sprite/z)

---

<div class="post-metadata">

**Author:** ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)\
**Post date:** [March 17, 2020, 2:57am UTC](https://forum.makecode.com/t/lives-on-enemys/1418/3 "2020-03-17T02:57:26Z")

</div>

> **[spritelife](https://arcade.makecode.com/60126-31383-65491-84460)**
>
> sprite lifes helper blocks

Built some helper blocks for my students, may help.

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [March 17, 2020, 5:22am UTC](https://forum.makecode.com/t/lives-on-enemys/1418/4 "2020-03-17T05:22:20Z")

</div>

That’s a great extension! Just so you know, in the block definition you can set it to have a variable dropdown for the sprite variable with with `%sprite=variables_get(mySprite)`; e.g.

```auto
//% blockId="set_sprite_life" block="set %sprite=variables_get(mySprite) life to %lives"

```

will show up as

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/e8238d2e554f3391e2f8339ef7960b0372c8d3e6.png)

also, if you want to make that a full extension github extension in the future, might be useful to know that each sprite has a `.data` field that you can store data in; e.g. `sprite.data["SPRITE_LIFE_EXTENSION_KEY"] = lives;`

---

<div class="post-metadata">

**Author:** ![felixtsu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/felixtsu/32/12024_2.png) [@felixtsu](https://forum.makecode.com/u/felixtsu)\
**Post date:** [March 17, 2020, 12:26pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/5 "2020-03-17T12:26:44Z")

</div>

Wow! With your help the usability finally catches up with the built-in blocks. Thank you!

A quick modification to an extension.

> **[felixtsu/pxt-spritelife](https://github.com/felixtsu/pxt-spritelife)**
>
> Contribute to felixtsu/pxt-spritelife development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)\
**Post date:** [March 17, 2020, 1:23pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/6 "2020-03-17T13:23:36Z")

</div>

Don’t forget to create a release for your extension!

---

<div class="post-metadata">

**Author:** ![codebott578](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/codebott578/32/690_2.png) [@codebott578](https://forum.makecode.com/u/codebott578)\
**Post date:** [March 17, 2020, 9:36pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/7 "2020-03-17T21:36:57Z")

</div>

Ok thanks

---

<div class="post-metadata">

**Author:** ![codebott578](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/codebott578/32/690_2.png) [@codebott578](https://forum.makecode.com/u/codebott578)\
**Post date:** [March 17, 2020, 10:34pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/8 "2020-03-17T22:34:59Z")

</div>

But how do I transfer the extension to my project?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [March 17, 2020, 11:06pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/9 "2020-03-17T23:06:46Z")

</div>

@codebott578 in the toolbox there is an “+ extension” button in the advanced section.

To add any GitHub extension:

1. Press “+ extension”
2. Get the GitHub the URL for the extension,
3. Paste it into the search box that appears, and hit enter
4. You should see a card for the extension with the name displayed. Click it and the blocks should show up in the toolbox

Make sure you back up your game before you add any extensions!

---

<div class="post-metadata">

**Author:** ![codebott578](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/codebott578/32/690_2.png) [@codebott578](https://forum.makecode.com/u/codebott578)\
**Post date:** [March 17, 2020, 11:55pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/10 "2020-03-17T23:55:00Z")

</div>

Can you record how to do it. That will give me a better idea of how to do it

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [March 18, 2020, 12:00am UTC](https://forum.makecode.com/t/lives-on-enemys/1418/11 "2020-03-18T00:00:10Z")

</div>

Here you go! I should mention that this is not a Microsoft extension and I haven’t tested it out yet.

 ![2020-03-17 16.57.29](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/448c4ee55bfa3920b7f81938cd7d2a04b6e607ba.gif)

---

<div class="post-metadata">

**Author:** ![codebott578](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/codebott578/32/690_2.png) [@codebott578](https://forum.makecode.com/u/codebott578)\
**Post date:** [March 18, 2020, 12:24am UTC](https://forum.makecode.com/t/lives-on-enemys/1418/12 "2020-03-18T00:24:42Z")

</div>

Thanks! That explains it.🙂

---

<div class="post-metadata">

**Author:** ![reyhanPanci256](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/reyhanpanci256/32/1770_2.png) [@reyhanPanci256](https://forum.makecode.com/u/reyhanPanci256)\
**Post date:** [April 7, 2020, 1:24am UTC](https://forum.makecode.com/t/lives-on-enemys/1418/13 "2020-04-07T01:24:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/c6df7092f272cdadceba707c1b1cd489e0493736.png)

how?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [April 7, 2020, 4:39pm UTC](https://forum.makecode.com/t/lives-on-enemys/1418/14 "2020-04-07T16:39:53Z")

</div>

@reyhanPanci256 are you connected to the internet?
