dis446 / Shelter-Survival-Text-Based

An open source, text based version of the popular Bethesda Fallout Shelter game.
8 stars 7 forks source link

Can't refer to variables defined in main file #18

Closed dis446 closed 8 years ago

dis446 commented 8 years ago

In the class files, I can't refer to variables defined in the main file. So I have to two options.

  1. Declare them as variables in the classes ( Don't know if they will work)
  2. Make the code more functional. As in pass to the class all the variables that it needs to know. For example, the human class gives stats specific to the player. This is currently done by checking if the length of the people list is zero.
dis446 commented 8 years ago

This is causing major issues, since the class init constructor used some global variables to determine some stuff. i.e. if ""len(people)==0:""" then it is assumed that the human being created is the player.

Talkyn commented 8 years ago

Why don't you simply instance Human and assign to a player variable at game creation?

"player = Human(attributes, more attributes)"

Then you can easily refer to the player any time you want, simply "player.method" or "player.attribute"

The reliance on globals means they are permeated in the code. Until a large refactor is done to assign them to all to a class, there will be all sorts of headaches with any organizational attempts, including simply separating files.

dis446 commented 8 years ago

That's genius! So I should just keep the player seperate from all the others. Up till now, the player was the first entity in the 'people' list. Great idea!