Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Please read the forum rules before posting.

Check if you are posting in the correct category.

The Off Topic section is not meant for discussing Cookie Clicker.
⚠️ The DashNet forums will be shut down on September 12th 2019.⚠️

Please see here for more information.

please help with making a building disappear and replaced with a new one

Korrupt86Korrupt86 Posts: 87Member ✭✭
edited December 2018 in Developer's Lounge
My game is based around causing damage and when you take all HP from 1 building it will disappear and be replaced with a new/stronger one. so far i can get my heroes to cause damage but when it reaches 0 HP it just stays there and wont replace with next one.

Here is a link to my game (All images and costs are purely placeholders right now taken from previous IGM projects so dont worry if names and description make no sense)

Battle Heroes.

You can use the pastebin link to look over my code.

I would really appreciate the help. This is the last obstacle for me before I can focus 100% on game content. Thanks in advance.


  • firefliesfireflies Posts: 56Member ✭✭
    I am not sure which 0 item you are referring to on the game, but you can have "hidden when 0" for things, so that if you have 0 of them, they won't be visible... you can also have "req: (something)" when you want something to be invisible when another thing is 0 (such as a resource)

    Hope that helps, if you have any more questions, just ask :)
  • Korrupt86Korrupt86 Posts: 87Member ✭✭
    edited December 2018
    I have 14 buildings which act as enemies and 12 buildings which act as your attacking heroes, Enemy building 1 has 1000 HP (EnemyHP1, See below), when the heroes get it to 0 HP it just stays and you can continue to attack it with 0 HP. its supposed to disappear and be replaced by building 2 using this code:

    on reload:
    EnemyHP1 = 1000
    EnemyHP2 = 5000
    EnemyHP3 = 10000
    EnemyHP4 = 100000
    EnemyHP5 = 1000000
    EnemyHP6 = 10000000
    EnemyHP7 = 100000000
    EnemyHP8 = 1000000000
    EnemyHP9 = 10000000000
    EnemyHP10 = 100000000000
    EnemyHP11 = 1000000000000
    EnemyHP12 = 10000000000000
    EnemyHP13 = 100000000000000
    EnemyHP14 = 1000000000000000
    AllyDmg2 = 2
    AllyDmg3 = 31.4
    AllyDmg4 = 193
    AllyDmg5 = 838
    AllyDmg6 = 4105
    AllyDmg7 = 22723
    AllyDmg8 = 204683
    AllyDmg9 = 1448277
    AllyDmg10 = 8910946
    AllyDmg11 = 63051235
    AllyDmg12 = 315256175

    if (EnemyHP1 > 0 and Enemy1 > 0)
    EnemyHP1 = EnemyHP1 - $TotalDmg
    Enemy1HP = EnemyHP1
    else if (EnemyHP1 <= 0 and Enemy1 > 0)
    Enemy1 = 0
    Enemy2 = 1

    if (EnemyHP2 > 0 and Enemy2 > 0)
    EnemyHP2 = EnemyHP2 - $TotalDmg
    Enemy1HP = EnemyHP2
    else if (EnemyHP2 <= 0 and Enemy2 > 0)
    Enemy2 = 0
    Enemy3 = 1

    and so on up until enemy 14.

    Is this code incorrect?


    I have an idea i will try tomorrow, if it doesn't work i will have to work out a different way of coding it.
  • firefliesfireflies Posts: 56Member ✭✭
    I don't know of an on reload event, but an on click event would be better for the click that removes the hp, or if it is automatic, have a building, upgrade or even a hidden upgrade do an on tick check - essentially the same action that reduces the hp to 0 should also check if the hp is 0 and enact the change then
  • AmnesiacWizardAmnesiacWizard Posts: 2Member
    I think I know how to do what you are trying to do. Use buttons instead of buildings. You can set conditions for when the button is and isn't shown. It works extremely well. Here is the relevant code for having an enemy appear once, and then disappear forever once health is depleted. Many ways to do this but this is just one of them. My game is g=1DVT2AXE. Its NOT released yet but it might help to see what the code does. Hope this helped. If you have any more questions just ask.
    desc:The only thing that matters.
    desc:Stores multiplier value
    desc:Displays relevant health information.
    on tick:
    if (health>0) show health
    if (health=0) hide health
    desc:For reading purposes only!
    on click:yield 1 knowledge
    no text
    name:Land Lord
    desc:He's come to collect your rent!
    on click:
    lose 1 health
    yield 1 multiplier
    no text
    on tick:
    if (knowledge>=20 and multiplier<=50) show landlord
    if (knowledge>=20 and no health and multiplier<=50) health=50
    if (multiplier>50) hide landlord
  • Korrupt86Korrupt86 Posts: 87Member ✭✭

    I think I know how to do what you are trying to do.

    Thanks but mine was just a simple problem such as hidden when 0 lol. when I added that to the template it worked. thanks for taking the time to explain though.

Sign In or Register to comment.