# Yet Another Dueling Grounds Difficulty: Shield Appears to not Work

**URL:** <https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004>\
**Category:** Level Help\
**Created:** [August 13, 2019, 5:42pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004 "2019-08-13T17:42:38Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobmcphe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bobmcphe/32/10647_2.png) [@bobmcphe](https://discourse.codecombat.com/u/bobmcphe)\
**Post date:** [August 13, 2019, 5:42pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/1 "2019-08-13T17:42:38Z")

</div>

I have looked at many, if not most, of the related posts on this, to no avail. I am not sure that the problem is my code, per se, but I suspect more of my strategy. Nevertheless, I am quite stuck.

I do not have some of the features other people have, (e.g. hero.wait ()) and so on, which I would be inclined to use. I have the shield equipped, however, and it seems to not help.

Here is my code:

```python
while(true) {
    var badguy = hero.findNearestEnemy();
    if (badguy) {
    hero.cast("chain-lightning", badguy);
 
        if (hero.isReady("chain-lightning")) {
             hero.cast("chain-lightning", badguy);
            }
        else {
        hero.shield();
         }
    }
}

```

Thank you in advance, I appreciate being able to learn Javascript in this bite-sized and enjoyable way.

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [August 13, 2019, 6:09pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/2 "2019-08-13T18:09:21Z")

</div>

Hello, and welcome to the forum. CodeCombat is definitely a great way to learn Javascript and overall code structure and syntax.

I believe that one line is causing you problems, the first chain-lightning command. Chain-Lightning has a cool-down period of 20 seconds and can only be used again after that time. If you call that command when your hero isn’t ready, your code won’t run anything until it completes that command (potentially waiting 20 seconds doing nothing). You are on the right track with checking before you call the command in the next set of code. Eventually, you will always want to check if you can run a command before calling it. The earlier levels are timed out just right so you don’t run into this problem.

---

<div class="post-metadata">

**Author:** ![bobmcphe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bobmcphe/32/10647_2.png) [@bobmcphe](https://discourse.codecombat.com/u/bobmcphe)\
**Post date:** [August 13, 2019, 6:32pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/3 "2019-08-13T18:32:20Z")

</div>

Thank you. So, if I understand right, this is getting in the way of the use of the shield? I have ran into same problem even when I ran `hero.attack()`.

In fact, I just updated my code to this:

```python

while(true) {
    // Find and attack the enemy inside a loop.
    // When you're done, submit to the multiplayer ladder!
    var badguy = hero.findNearestEnemy();
    if (badguy) {
    hero.attack(badguy);
    then; 
    hero.shield();
    
    }
        else {
        hero.shield();
         }
    }

```

And again, the two guys strike at the same time, and die, at the same time. Thanks again.

(update) I am not sure why the code is all funny…with the red and what not…

Also, removing the `then;` changes nothing either.

---

<div class="post-metadata">

**Author:** ![bobmcphe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bobmcphe/32/10647_2.png) [@bobmcphe](https://discourse.codecombat.com/u/bobmcphe)\
**Post date:** [August 13, 2019, 6:33pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/4 "2019-08-13T18:33:38Z")

</div>

I am not sure why the code is all funny…with the red and what not…

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [August 13, 2019, 7:10pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/5 "2019-08-13T19:10:55Z")

</div>

Did you remove just the `then;` like below? This will run both commands every time your hero finds the badguy. I chose a good sword and was able to beat the simple CPU. Now start adding your other commands to get a better attack.

```python
    if (badguy) {
    hero.attack(badguy);
    hero.shield();
    }

```

FYI… The apostrophe is handled like single quotations and triggers the red until you close it.

```python
Just an ' example' to show "how this works"

```

---

<div class="post-metadata">

**Author:** ![bobmcphe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bobmcphe/32/10647_2.png) [@bobmcphe](https://discourse.codecombat.com/u/bobmcphe)\
**Post date:** [August 13, 2019, 7:35pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/6 "2019-08-13T19:35:51Z")

</div>

Yes, I did remove it. I even copied and pasted what you just provided now. Allow me to copy and past the new ammended code:

```python
    var badguy = hero.findNearestEnemy();
    if (badguy) {
    hero.attack(badguy);
    hero.shield();
    }
        else {
        hero.shield();
         }
    }

```

No matter what I do (basically) my guy always dies in one blow. But, like I said, I have a shield equipped, and am using the command – I am at a bit of a loss.

---

<div class="post-metadata">

**Author:** ![Shurutsue](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/shurutsue/32/10314_2.png) [@Shurutsue](https://discourse.codecombat.com/u/Shurutsue)\
**Post date:** [August 13, 2019, 7:38pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/7 "2019-08-13T19:38:58Z")

</div>

You can also add “javascript” in the same line of the triple `

for example:  
```javascript  
// Yes this isn’t going to mess up the colors anymore!  
```  
results in:

```javascript
// Yes this isn't going to mess up the colors anymore!

```

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [August 13, 2019, 8:00pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/8 "2019-08-13T20:00:53Z")

</div>

Cool!! 🤩 I didn’t know that trick!!

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [August 13, 2019, 8:12pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/9 "2019-08-13T20:12:00Z")

</div>

Dying on one blow? The code isn’t as much the issue, but likely the rest of your gear. It sounds like you don’t have good armor to boost your overall health score.

When you attack, you open yourself up for an attack and take the full damage. And depending on the shield, it will only absorb a certain percentage of the damage. For fun, you can comment out the attack line using the # symbol just to see how the shield command provides some protection.

With the way your code is setup, you will always attack once and then shield once as long as your hero can find an enemy.

---

<div class="post-metadata">

**Author:** ![bobmcphe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bobmcphe/32/10647_2.png) [@bobmcphe](https://discourse.codecombat.com/u/bobmcphe)\
**Post date:** [August 13, 2019, 8:13pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/10 "2019-08-13T20:13:39Z")

</div>

Is the shield perpetual? Or is it something that, for example, lasts only a 1s? I can try to add some more regarding health.

UPDATE: I upgraded my armor, and the opponent did as well! Using the code just lead to bashing each other until my guy died. At least there is more time to interact and strategize now. I will keep playing around, thank you.

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [August 13, 2019, 8:24pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/11 "2019-08-13T20:24:59Z")

</div>

Every method has its attributes: How long it takes to use? How long it will stay in use (spells or rings) How long it takes to use again (cool-down). When you click on the methods in the middle bar, it expands to show some of the primary attributes for each piece of gear.

For example: I have the Deflector Shield currently equipped. The shield method takes .324 seconds to run and block 79% of the damage. A short time to protect you. To keep the shield “active”, place it after a bunch of if/elif statements for your bigger attacks that take cool-down time and have shield as the else until you are ready to reuse them.

![Shield%20attribute](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/c/c6519bf75f8b5eb5c46f813455eb34167218bee3.jpeg)

---

<div class="post-metadata">

**Author:** ![bobmcphe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bobmcphe/32/10647_2.png) [@bobmcphe](https://discourse.codecombat.com/u/bobmcphe)\
**Post date:** [August 13, 2019, 8:25pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/12 "2019-08-13T20:25:04Z")

</div>

Ok, I did what you said…tried just using shield. BIG DIFFERENCE. So, the shield now is staying up, whereas before, I don’t even think I saw it come up. Starting to get somewhere…

---

<div class="post-metadata">

**Author:** ![bobmcphe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bobmcphe/32/10647_2.png) [@bobmcphe](https://discourse.codecombat.com/u/bobmcphe)\
**Post date:** [August 14, 2019, 1:26pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/13 "2019-08-14T13:26:38Z")

</div>

Got it to work, though, still not 100% sure what the hang-up was. Thanks again. I will be back soon, I am sure.

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [August 14, 2019, 4:38pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/14 "2019-08-14T16:38:03Z")

</div>

Just to clarify, the reason your old code wasn’t working is that until you kill him/her there will always be a “badguy”, so the `else` will never trigger. And the `hero.shield();` you put after the `hero.attack();` lasts only .324 seconds (As Brooksy said), so you’ll attack, shield for a small amount of time, attack, shield etc… etc…

```javascript
    var badguy = hero.findNearestEnemy();
    if (badguy) {
        hero.attack(badguy); 
        hero.shield(); // this lasts for a short amount of time before looping back to the line above.
    }
        else {
        hero.shield();
         }
    }

```

The way to keep your shield up is to do this (this wouldn’t be a great tactic in Dueling grounds, but it might work better in Cavern Survival):

```javascript
while (true) {
    var enemy = hero.findNearestEnemy()
    if(enemy) {
        if(hero.isReady("cleave") {
            hero.cleave(enemy);
        }else {
            hero.shield();
        }
    }
}
// A similar tactic could also be used with power-up or maybe even with fire-traps! 
// It's up to you.

```

I hope this helps explain it a bit more to you. If you have more difficulties, could you post your current code so we can help you.  
Thanks  
🦁 🦁 🦁

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 21, 2020, 8:04pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/15 "2020-05-21T20:04:21Z")

</div>

yes he is right（@Deadpool198）

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 21, 2020, 8:21pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/16 "2020-05-21T20:21:14Z")

</div>

if it still doesnt shield perhaps try reloading page, reloading code, or the worst option(RESTART THE ＷHOLE ＧAME)

---

<div class="post-metadata">

**Author:** ![EpicCoder999](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/epiccoder999/32/12768_2.png) [@EpicCoder999](https://discourse.codecombat.com/u/EpicCoder999)\
**Post date:** [May 21, 2020, 10:29pm UTC](https://discourse.codecombat.com/t/yet-another-dueling-grounds-difficulty-shield-appears-to-not-work/19004/17 "2020-05-21T22:29:57Z")

</div>

or destory ur pc and get a new one
