[ SOLVED ] Help on functions accepting multiple parameter!


#1

I don’t understand how to make a function that accepts a parameter. Here is my code:

Define a function with multiple parameters, and use it.

Move to a point. If an enemy is there, attack it.

def checkAndAttack():
enemy = hero.findNearestEnemy()

hero.moveXY(10, 30)
if enemy:
    hero.attack(enemy)

while True:
enemy = hero.findNearestEnemy()
hero.moveXY(10, 30)
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
hero.moveXY(30, 10)
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
hero.moveXY(50, 30)
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
I’m thinking that the line where it say enemy = hero.findNearestEnemy in the def is a parameter, but I’m not sure. Any help, I would appritiate it?


#2

Please learn to post your code properly. It’s really easy and only requires a very small amount of effort.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.


#3

Sorry, I didn’t know.


#4

Don’t know what exactly?

Nevermind, I misread your post.

That’s okay, you can edit the post and redo it. Just click the </> button first.


#5

How to post my code properly, and I truly appreciate your help but I already submitted and won this level. Sorry, and thank you.


#6

Great! Just for future reference, I hope this answers your question. Just put a comma between them if you have more than one parameter like this:

anyFunctionName(parameter0, parameter1, parameter2)

Parameter


#7

someone put this to solved.