SOLVED: findByType capitalization error


#1

Here is my relevant code:

def commandSoldiers():
    peasant = self.findNearest(self.findByType("peasant"))
    for soldier in self.findByType("soldier"):
        if peasant:
            self.command(soldier, "defend", peasant)

It tells me that I have an uppercase or lowercase problem on line 2 and tells me, “Try self.findByType().” I have received this message in other commands as well. What should I do?


#2

Hmm, that’s strange. You definitely have glasses equipped with the findByType method? Which level is it?


#3

I’m using the Enchanted Lenses (and enjoying them very much). The level is The Two Flowers.


#4

The Crude Glasses, Wooden Glasses, and Mahogany Glasses are restricted. Did someone maybe miss restricting a few pairs? Is there perhaps something I’m not getting with how we’re supposed to solve this level?

I changed my code to this:

def commandSoldiers():
    for soldier in self.findByType("soldier"):
        if peasant:
            self.command(soldier, "defend", "Hector")

Now it tells me that “tmp60[tmp61] is not a function” and won’t even highlight the line with the error in red for me. It does have some green on the second line, though.


#5

It only shows on the “Restricted” list what you have bought that is restricted. Also, where do you define peasant?


#6

I had two ways of doing it: In the first, I used self.findNearest(self.findByType("peasant")) to identify the peasant; in the second, I called the peasant by name (Hector) and didn’t use the peasant variable at all. (I had also tried self.findByType("peasant")[0].)


#7

Well, then why do you check for peasant in your second version if you didn’t use it at all?


#8

The only ways I can think of that’s breaking the code are that the stack trace is blowing up (basically impossible, unless maybe on Summit’s Gate), or you redefined self or self.findByType (very unlikely too).

Also I don’t think you can defend a target specified by just their ID (yet); it has to be a unit or a position.


#9

Update: I saw that Hector survives without code, but the hero doesn’t. For this reason, I decided to try doing nothing but summoning soldiers and shielding, but self.shield() throws me a “tmp20[tmp21] is not a function” error as well. This is ridiculous since I’m using the steel shield which definitely has a “shield” function. I checked and I’m definitely using Python.

[quote=“ChronistGilver, post:7, topic:4723, full:true”]
Well, then why do you check for peasant in your second version if you didn’t use it at all?
[/quote]Eh, good point. Unfortunately, that doesn’t solve the problem.

[quote=“trotod, post:8, topic:4723”]
Also I don’t think you can defend a target specified by just their ID (yet); it has to be a unit or a position.
[/quote]Okay, I changed it back, and now I’m getting the original capitalization error. For clarification, here is my code:

def commandSoldiers():
    peasant = self.findByType("peasant")[0]
    for soldier in self.findByType("soldier"):
        if peasant:
            self.command(soldier, "defend", peasant)

[quote=“trotod, post:8, topic:4723”]
The only ways I can think of that’s breaking the code are that the stack trace is blowing up (basically impossible, unless maybe on Summit’s Gate), or you redefined self or self.findByType (very unlikely too).
[/quote]I’m not sure what that means, though I someday will, I’m sure. :confused: Summit’s Gate is also giving me trouble with my code and I tried it before I started The Two Flowers, I believe. I’m using Firefox 40.0.2 and have crashed the current version a few times, especially on Zero Sum and maybe The Trials. I crashed it before version 40 a lot.


#10

I don’t get the error when I use your code. Strange. Try defending peasant.pos instead.


#11

It didn’t work. Is there some way to make the level forget that I ever typed anything (not just resetting the code)? I’m not sure what’s wrong, but I am sure it’s not running correctly.


#12

After resetting the code, reload the page. This shouldn’t leave anything behind AFAIK.


#13

Snap. It didn’t work.


#14

I know of no remaining course of action but to summon the power of He Whose Name Must Not Be Spoken. We plead for your help, @nick!


#15

@GundericusTheMighty I checked out your code and found the problem. Your method for what your hero is supposed to do is defined as def self():. So now instead of self referring to your hero, it then refers to that method. Try naming it def chooseHeroAction(): or something like that.

You also need to define the peasant in pickUpNearestCoin and then you’ve got it.


#16

[quote=“nick, post:15, topic:4723”]
I checked out your code and found the problem. Your method for what your hero is supposed to do is defined as def self():. So now instead of self referring to your hero, it then refers to that method.
[/quote]Whoa. I had no idea it could do that. Thanks much!