Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

Môsi

A tiny game editor you can use on your phone or in your browser · By sg

help with hp variable

A topic by Ash Attack created Nov 03, 2019 Views: 103 Replies: 3
Viewing posts 1 to 4

Hello! 

I was wondering if anyone could give me advice on how to implement a hp system? I've played around a lot with the variables and ifs, but I don't think I'm doing it right. Admittedly, I'm not much of a coder outside of fiddling with Twine. ^-^; 

For more info, here's what I'm trying to accomplish: 

I want the avatar to have 5 points of health. When the avatar bumps into certain object, lose 1 point of health. When the health reaches zero, have a dialogue box pop up and then the avatar moves back to the beginning. 

If it's not something I can do within Mosi, no biggy! I'm still having lots of fun and can the point of the game across. 

Thank you~!

(3 edits) (+1)

I'm not good in english, but:
1) at first

 {set-var hp 5} 

we need to set some "HP" variable, on "world" script

2) At enemy/danger sprite:

{dec-var hp 1}
{if {lte {var hp} 0}}
{move-avatar start 3 3}
{/if}

* (1-st line)  "dec-var" - it's like "hp - 1"  ("dec-var" - decrease variable)

* (2-nd line) lte - it's like "if (hp <= 0)" ("lte" - low then or equal)

* (3-rd line) move-avatar to level with name "start" on X,Y axis (we need have "start" level and don't have any walls on 3,3 axis)

* (4-rd line) if ending state

I hope I don't make errors here!

(1 edit) (+1)

Advanced Script with text:

{dec-var hp 1}
You get hurt.{b}
Your life is {var hp}!{b}
{if {lte {var hp} 0}}
You're dead!
{move-avatar start 3 3}
{/if}
(+1)

This has really helped, thank you!