1

So, kind of new to python, as I kinda started learning it a few months ago. I'm currently trying to make my own game (not expecting it to be super good, but I want it to work decently) The game is basically going around a dungeon, fighting monsters, leveling up, doing puzzles, and then fighting the final boss. Basically, your average RPG game. I am making it all text though. Currently stuck on a bit of code for my levelup script and my stats script. I have a variable in stats called "constitution", and whenever i level up (if exp >= expmax) i add 3 to the value of constitution. (starts out at 10)

    import LevelUP
    constitution = 10

that one is my code in the Stats script, and the one is the code in the LevelUP script.

    import Stats
    level = 1
    expMax = 100
    exp = 100
    if exp >= expMax:
      level=level+1
      exp = 0
      expMax = expMax+expMax*0.5
      Stats.constitution = Stats.constitution+3
      Stats.strength = Stats.strength+4
      Stats.dexterity = Stats.dexterity+4
      Stats.intelligence = Stats.intelligence+3
      Stats.wisdom = Stats.wisdom+3
      Stats.charisma = Stats.charisma+2
      Stats.luck = Stats.luck+2

This is the error that comes up

    Traceback (most recent call last):
      File "main.py", line 3, in <module>
        import Stats
      File "/home/runner/Stats.py", line 1, in <module>
        import LevelUP
      File "/home/runner/LevelUP.py", line 9, in <module>
        Stats.constitution = Stats.constitution+3
    AttributeError: module 'Stats' has no attribute 'constitution'
    exited with non-zero status

Kind of new to the site, but I have looked around for something like this and all i could find was using print() in different scripts.

Zarfus
  • 13
  • 2

1 Answers1

0

There is a cyclic import in your code. Please see Circular imports in Python with possible undesired behaviours.

Anyway, it seems that your Stats module does not need LevelUp (does it?). I suggest rethinking your architecture.

J.M. Robles
  • 614
  • 5
  • 9
  • Thanks! I appreciate you showing me that. I ended up sticking all the code in the LevelUp module into the Stats module, and it worked perfectly. With the way I had my code, I did need both imported into each other, as some variables in stats had uses in Levelup, and some variables in Levelup had uses in Stats. – Zarfus Nov 05 '17 at 21:41