# Level Idea: Find the shortest path to the health tonics

O no! You were bitten by a snake! Your hit points are slowly depleting… health potions(Alternately some plant you need…or something like that) spawn “randomly” on the map (This could be done in a smart way to avoid clumps etc)… and you are given an array of them with coordinates.

Using only up,down,left,right commands you need to go to each in a fairly intelligent way so that you can get enough before you die.

After a certain number are collected your HP stops depleting.

So it’s a general traveling salesman problem, the difficulty could be adjusted by how much health you start with, other things on the map, or how fast you loose health. It could be as simple as go to each in turn by finding the distance to each using the Pythagorean theorem and go to the closest one to something requiring a better algorithm because the potions are arranged in such a way that some would be left behind using that simple algorithm.

Is it worth trying to implement? Should I make an easy or hard version?

1 Like

So… I’m just playing with the level editor at http://codecombat.com/editor/level/52c086d5b7ec6288680019c6#.

Step1 is to make him start loosing health over time.

My first thought was to set the healthReplenishRate to a negative number. … and he did die after the correct number of moves but the issue is the health bar doesn’t update. So you are just walking along minding your own business and thud…dead.

My second thought was to make an invisible guy that would keep causing damage… but that’s a bit too crude and I would need him to be invisible, his weapon invisible, and him to not show up on the list of characters when starting the level . I also tried the ai.attacksSelf… but watching him perform his attack sprites doesn’t make sense and he quit executing his move commands.

My third thought was to try to add a second programmable method to the main character. But it just didn’t run and I’m guessing if it did the programmer could see it in some future version so that would be bad.

So if anyone has any great ideas on how to have him die over time let me know I’ll probably mess with it a bit more as I keep finding things in the editor.

This does sound like a promising level idea. I’d love to help get it implemented. Let me see. The reason his health bar isn’t updating is because the health replenishment doesn’t trigger the `health` property to be flagged as changed. (We serialize as few Thang properties as possible for performance reasons, and when the code doesn’t mark one as changed, it doesn’t get serialized.) I’ve just made the `Attackable` Component smarter about that; give it another shot.

You might want to publish this one, too, so people can check it out.

Thank you! Removing health over time is working.

I’m having issues with a couple other major bugs right now…

The first issue is that if I move him to a potion, instead of picking it up the game freezes. In the javascript console I have TypeError: value.split is not a function value = value.split(’\x1E’); app.js line 17619.

Another issue is when I push the play button it isn’t adding the recent changes, they only appear after I hit the save button. Not sure if this is just something that changed since yesterday. If it is intentional then n/m about the bug but I’ll just mention I kind of liked it the other way around since I like to get to a good stopping point before I write a message about changes I made and I will want to make little changes and reload it MANY times for testing.

Other small issues:
The object Spear - Spear2… won’t let me select it so I can’t delete it.

Thanks again and happy holidays!

Yup, bugs all around. Working on these tonight; will update soon when fixed.

This TypeError issue is really stumping me. I found a bug that should never have worked, so if I update it to the proper code, Snake Bite works–but then every other level with a Collectable breaks. Weird! I’ll keep digging.

Finally realized what was going on and fixed this. I think all the other bugs you mentioned are also fixed now, and we’ve added a full-blown Effects System which should be able to much more naturally do things like having guys get poisoned.

You can add the Effects System to your level, check out any of the magic.Casts[Something] Components to see how they add Effects, and hook up some simple Component that just adds a ‘poison’ effect that decreases health over time. (The healthReplenishRate thing happens to work for this property, but now much more flexible things can be done with any properties on the fly based on what happens in the game.)

Sorry this took so long to fix!

Awesome, ty for looking into it. I’m a bit swamped right now but hopefully at some point I’ll be able to look into those features.