My code isn't running in Sorcerer's Blitz

My code in sorcerer’s blitz aint working.
I have wrote down many functions and called them in a “while-true” loop, they wouldn’t run. One of the default functions had a while-true loop, and it was running even though I wasn’t calling it, so i commented it. Still nothing works…
Can someone please help?

Welcome to the forum! :smiley:
We hope you have a lovely, enjoyable, and fun time here on the CodeCombat Discourse.
This forum is a homely place, where you can share ideas, share made levels, report bugs, get help on code, and so much more!
We hope you review this topic for all the rules of the forum!
Thanks and enjoy your time here!!!
:partying_face:
Can you please post your code? :smiley:

2 Likes
"My Code
count = 0;

def choose(collector):
    global count
    count += 1
    return ['fire', 'water', 'earth'][count % 3]

#def collectHandler(data):
 #   unit = data.target
    #while True:
     #   if unit.item:
      #      unit.bring()
       # else:
        #    fruit = unit.findNearestFruit()
         #   if fruit:
          #      unit.pick(fruit)

def shieldDestruction(enemyShield):
    if enemyShield and enemyShield.mana == "fire" and hero.water >= 7:
        hero.cast("water-beam")
    elif enemyShield and enemyShield.mana == "water" and hero.earth >= 7:
        hero.cast("earth-beam")
    elif enemyShield and enemyShield.mana == "earth" and hero.fire >= 7:
        hero.cast("fire-beam")

def pickShield(enemyHero):
    if enemyHero.water >= 7 and hero.earth >= 2:
        hero.cast("earth-shield")
    elif enemyHero.earth >= 7 and hero.fire >= 2:
        hero.cast("fire-shield")
    elif enemyHero.fire >= 7 and hero.water >= 2:
        hero.cast("water-shield")

def specialAttack():
    if hero.fire >= 5:
        hero.cast("fire-burn")
    elif hero.water >= 5:
        hero.cast("water-refresh")
    elif hero.earth >= 5:
        hero.cast("earth-grow")

def transformCollectors():
    hero.spawnCollector()
    collectors = hero.findMyCollectors()
    for collector in collectors:
        if collectors[collector] % 2 == 0:
            if hero.fire >= 4:
                hero.transform(collector, "thief")
        else:
            if hero.earth >= 4:
                hero.transform(collector, "grower")

def commandCollectors():
    collectors = hero.findMyCollectors()
    for collector in collectors:
        if collector.type == "thief":
            victim = unit.findNearestFriend()
            if victim and victim.type == "grower"and victim.item:
                if unit.distanceTo(nearest) < 5:
                    unit.special(nearest)
                else:
                    unit.move(nearest.pos)
        elif collector.type == "grower":
            fruit = collector.findNearestFruit()
            if fruit:
                if collector.distanceTo(fruit) > 5:
                    collector.move(fruit.pos)
                else:
                    collector.special()

def attack():
    if hero.water >= 7:
        hero.cast("water-ball")
    elif hero.fire >= 7:
        hero.cast("fire-ball")
    elif hero.earth >= 7:
        hero.cast("earth-ball")

while True:
    enemyHero = hero.findEnemyHero()
    enemyShield = enemyHero.getActiveShield()
    transformCollectors()
    commandCollectors()
    attack()
    shieldDestruction(enemyShield)
    #pickShield(enemyHero)
    specialAttack()


I am looking into it.

Aha!
There is no hero.findEnemyHero()
It’s hero.getEnemyHero()
:joy:

Thanks, I’m going to fix it

Nothing new, only collectors are working, it actually says in the autocomplete it is findEnemyHero, so im not sure. it isn’t giving me any error for anything

Look @ the console log. I don’t think that error is your fault. I copy pasted your code, to try to make it work, and I received this.
|Ptah’s Cyril| Hero Placeholder had new Programmable problem: plan Line 352: TypeError: Tried to load an unsafe native value into the interperter:object / Rod 3.1
@staff you might want to look at this.
Do ctrl shift j to see console

Thanks a lot for your help @RangerGrant9307

1 Like

how much time do the @staff usually take to reply?

They are busy, so I do not think they are always ready to help with levels. Although we all are ready to help when we have time!

3 Likes

@Bryukh, would you be willing to take a look at this one?

for collector in collectors:
        if collectors[collector] % 2 == 0:

collector is an object, not an index.

2 Likes

I suppose you wanted to do something like

for collector in range(len(collectors)):

or

for c, collector in enumerate(collectors):
  if c % 2 == 0:
1 Like

This function is working, thanks a lot. Though the attack and special attack function still don’t work.

Please, read the documentation more carefully Specials are working, you just don’t command them correctly. Collectors and units are different. Also it’s better not to control units without event handlers

1 Like

how can I spawn a popper or an other person:

count = 0;

def choose(collector):
    global count
    count += 1
    return ['fire', 'water', 'earth'][count % 3]

def chaseAndPop(data):
    unit = data.target
    while True:
        enemy = unit.findNearestEnemy()
        if enemy:
            if unit.distanceTo(enemy) < 7:
                unit.special()
            else:
                unit.move(enemy.pos)

def collect(data):
    unit = data.target
    while True:
        if unit.item:
            unit.bring()
        else:
            fruit = unit.findNearestFruit()
            if fruit:
                unit.pick(fruit)


hero.on('spawn-runner', chaseAndPop)

You cannot spawn a popper, you got to spawn a collector first then transform it. For spawning a collector, you can check the methods tab.

1 Like

Which method do I use for spawning a warlock?

1 Like

The warlock is the “merger”, you have to do the same thing as you did with the popper. Spawn a collector then transform

1 Like