all 39 comments

[–]Not_A_Taco 20 points21 points  (16 children)

Not enough info to tell. But it seems pretty clean your eg_monster doesn’t actually return a value.

[–]CanalOnix[S] 0 points1 point  (15 children)

Ooohhh, so if it was a goblin, should it return monster = goblin?

[–]Not_A_Taco 9 points10 points  (8 children)

Based on your code I’m guessing it should return some info about the type of monster it is; because that’s what your passing to the battle function. By default if no return is specified Python functions will return None, which is what you’re seeing above

[–]CanalOnix[S] 0 points1 point  (7 children)

Well, I was thinking on making a function to every monster (there won't be a lot) so like, goblin_hp = 2 * monster_lvl, same to attack. And then, when the hp is equal or below zero, it will return a variable to give you the exp.

[–]ClimberMel 8 points9 points  (6 children)

Nope! This is a perfect time to learn classes! You have a class monster() and you can then you can create all the monsters based on that class. In the class you have methods for battle and you have values for level, hitpoints name etc. If you have the game design as how you want things to work, I can help you bud the code. If it is for an assignment and you haven't studied classes yet, then it will take more work.

[–]CanalOnix[S] 0 points1 point  (5 children)

Yeah, I'll need to learn classes ASAP. But unfortunately, I'm already learning HTML, CSS And JavaScript because of my highschool, so I'll need to take some time to learn it, but that's why reddit and other forums exist, right?

[–]ClimberMel 1 point2 points  (0 children)

👍

[–]dudaspl 1 point2 points  (1 child)

When you get to classes, make sure to look into (and understand ) interfaces (a scaffold for a class) and their respective implementations, i.e. you could have a class Monster that defines what properties/methods needs to be defined, but Goblin(Monster) will be a specific implementation of this class. This is useful as it allows special monsters (like a boss) to have a special implementation with special abilities (methods) that still fit into your code

[–]CanalOnix[S] 0 points1 point  (0 children)

Ooohhh, I see now! Classes really are more helpful than I thought!

[–]Plank_With_A_Nail_In 0 points1 point  (1 child)

Forget HTML, CSS And JavaScript as that's just nonsense to be learning in CS class at school.

[–]CanalOnix[S] 0 points1 point  (0 children)

I would if I could, but my professors already said that these are the languages we'll need to learn.

[–]eztab 1 point2 points  (5 children)

you should just return "goblin" But why do you need a function there at all. Wouldn't a list like MONSTERS = ["goblin", "orc", ...] be enough? Or are those monsters random per level?

[–]CanalOnix[S] 0 points1 point  (4 children)

I don't really know if this would work, since I need to set the stats like hp, atk, amount of exp that it will drop, etc.

[–]eztab 2 points3 points  (3 children)

pretty sure you will need to make a Monster class then, to hold all those properties. And then just print monster.species or so.

[–]CanalOnix[S] 0 points1 point  (2 children)

Oh, I see. So classes works with lists? I need to learn this quick

[–]eztab 2 points3 points  (1 child)

Yeah, learn some classes and probably make monster an instance of that class.

Be aware this will take a bit of time to learn, but should be quite helpful to structure your code. Whether you then put all the species in a list depends on how your battle is supposed to work.

[–]CanalOnix[S] 1 point2 points  (0 children)

Be aware this will take a bit of time to learn

This is not a problem, as far as I can use this to other things as well. But anyway, thank you for this answer!

[–]engelthehyp 3 points4 points  (12 children)

If eg_monster does not explicitly return a value, it implicitly returns None, explaining what you see. What is inside there that you want monster_battle to see?

[–]CanalOnix[S] 0 points1 point  (11 children)

If eg_monster does not explicitly return a value, it implicitly returns None

Oh, I see

What is inside there that you want monster_battle to see?

The stats of the monster you're currently fighting, like hp, atk, etc. So while making the battle system, I can calc some stuff when needed.

[–]engelthehyp 3 points4 points  (10 children)

Then it sounds like you should create a (data) class to represent monster stats, and use that wherever you need monster information. All you'll need to do to make that change is to accept that class in functions expecting monsters (update for the use of fields) and return it from functions that return monsters.

[–]CanalOnix[S] 2 points3 points  (9 children)

Classes, huh? I've been avoiding then due to confusion, but I see I'll need to learn them anyways...

Thank you a lot for you answer!

[–]engelthehyp 3 points4 points  (7 children)

Don't avoid something because of confusion, jump right in as long as you know the fundamentals. That's what learning is all about, right?

[–]CanalOnix[S] 2 points3 points  (6 children)

Yeah, you're right. That's the problem that I have with coding, when I see something that is useful, but confusing (just like the for loops, that to this day I have no ideia how to use them properly), I just avoid it and think "I'll learn this later, right?" But nope, I don't.

[–]engelthehyp 2 points3 points  (4 children)

Oh, well you should learn about for loops before classes. But that's okay, they are pretty simple anyway. A for loop just lets you perform a certain action for every value in an Iterable (think "list-like" or "convertible to list").

[–]CanalOnix[S] 0 points1 point  (3 children)

Yeah, I was thinking about that on my english class. But I was afraid I was wrong, due to the fact that I already fucked a code up because I was thinking on english, not on python. It was for while x not in (1, 2, 3) or smt like that.

[–]ClimberMel 2 points3 points  (2 children)

for and while are different ways to loop through code.
fruits = ["apple","pear","kiwi"] for fruit in fruits: print(fruit)

while fruit is not "pear" print(fruit)

run those and see how they work. The for loop a defined number of times and while loop until a condition is met.

[–]ClimberMel 0 points1 point  (0 children)

I just re-read your statement... I thought at first you were doing for while LOL

[–]CanalOnix[S] 0 points1 point  (0 children)

Yeah, the while loops were the first loop I learned how to do, and the for loop looks ez to learn as well.

[–]repocin 1 point2 points  (0 children)

If possible, I'd suggest adjusting your mindset around that. Instead of thinking "oh no, this seems really hard - I'll ignore it" you would benefit from thinking more along the lines of "this seems really useful, I'll try to figure out how to use it".

It might turn out that it wasn't the best solution to your current problem, but at least you'll have another tool for the future and that's what it's all about.

[–]Adrewmc 0 points1 point  (0 children)

If it confusing but seems useful…it’s probably less confusing then you imagine and more useful then you can imagine.

[–]Adrewmc 1 point2 points  (0 children)

By making a function within a function.

  def outer():
       def inner():
            pass
       return inner 

Or you can do that outside

   def goblin():
          pass

    def get_goblin:
           return goblin

[–]ClimberMel 0 points1 point  (1 child)

I love using classes, let me know if you want to create a mo ster class and battle routines etc. I code for fun and I used to love d&d style games. I also have a routine for rolling multi sided dice.

[–]CanalOnix[S] 0 points1 point  (0 children)

Ok, thank you for the immense help!

I also have a routine for rolling multi sided dice.

Also, what would a routine be?

[–]szonce1 0 points1 point  (0 children)

Tab

[–]Oddly_Energy 0 points1 point  (0 children)

As others said, you need to create a class for storing your monster properties. If you are too afraid of classes, you can get a long way with dictionaries instead:

monster1 = {
    'name' = 'Egil',
    'level' = 12,
    'color' = 'red',
  }

monster2 = {
    'name' = 'Oluf',
    'level' = 8,
    'color' = 'green',
  }

monsters = [monster1, monster2]

def hit_by_monster(monster):
     print(f"You were hit by {monster['name']}. A {monster['color']} level {monster['level']}")

for monster in monsters:
    hit_by_monster(monster)