I'm trying to get the variable 'money' from the file 'gold.py' to the file 'sandy1.py', but it seems impossible to get it over. I've tried from gold.py import money
but that just imports the whole thing and runs it.
Code from Sandy1.py:
from gold.py import money
import os
health = '100'
print 'Welcome to Sandy, the modern day text-based RPG! Type help to view commands.'
while 1 + 1 == 2:
main = raw_input('')
if main == 'suicide':
print 'Goodbye cruel world...'
health = '0'
print 'You died, type respawn to reset your health.'
main
if main == 'respawn':
print '*Your soul re-enters your body and you come back to life*'
health = '100'
main
if main == 'health':
print 'Your health is %r' % (health)
main = raw_input('')
if main == 'quests':
print 'Quest List: Gold, The Creep'
main
if main == 'Gold':
os.system('gold.bat')
main
if main == 'money':
print 'You have %d coins' % (money)
main
if main == 'help':
print 'Commands: suicide, respawn, health, quests, money'
Code from gold.py:
import os
money = '0'
health = '100'
print 'You are at home waiting for the mail, when the mailman comes rushing up to you'
print 'Mailman: Oi, you, on the way up a bear attacked me and I lost all my gold, could you go get it?'
type = raw_input('')
if type == 'ok':
print 'Mailman: Thanks so much!'
print 'Quest started: Gold'
print 'You begin to venture out of your garden and down the lane, when you encounter the bear. Do you fight it, hide from it, or run back home?'
part1 = raw_input('')
if part1 == 'fight it':
print 'You ready your fist to fight the bear, when it leaps on you and rips your head off in one. GAME OVER!'
health = '0'
os.system('sandy1.bat')
if part1 == 'run back home':
print 'You escaped with your life... But you failed the quest. GAME OVER!'
os.system('sandy1.bat')
if part1 == 'hide from it':
print 'You run and hide from it. It only just misses you. Whew, that was a close one.'
print 'As you carry on walking, you see a stream. Do you jump it, swim it, or go around it?'
part2 = raw_input('')
if part2 == 'swim it':
print 'You try to swim across but get eaten by a crocodile. GAME OVER!'
health = '0'
os.system('sandy1.bat')
if part2 == 'go around it':
print 'You start to run around it, but you run into another bear on the way. GAME OVER!'
health = '0'
os.system('sandy1.bat')
if part2 == 'jump it':
print 'You successfully jump over the stream and land safely on the other side.'
print 'There it is, the gold! You run over and grab the sack, then go back home, where you return it to the mailman.'
print 'You: Here you go, sir.'
print 'Mailman: Thank you. Here is some money for your deeds.'
print 'You gain 5 coins'
money = '5'
print 'Quest Completed: Gold'
os.system('sandy1.bat')
Sorry if it's messy, it's the best way I could transfer it.