Variables Don't Change When +1ed (Python 3.3) -
in previous post stated variable not change whenever added it. here current code , problem below it.
#creates random monsters xp points, leveling player, , adding upgrades #imports clint.textui import colored, puts import random sticks = 2 stumps = 2 stone = 0 iron_in = 0 gold_in = 0 diamond = 0 platinum = 0 w_sword = 1 w_shield = 1 items = ('sticks:' + str(sticks) + ' stumps:' + str(stumps) + ' stone:' + str(stone) + ' iron ingot:' + str(iron_in) + ' gold ingot:' + str(gold_in) + ' diamond:' + str(diamond) + ' platinum:' + str(platinum) + ' wooden sword(s):' + str(w_sword) + ' wooden shield(s):' + str(w_shield)) def game(): #start of game def start_game(): print(' hello player! welome text based game involving killing monsters, leveling up, crafting weapons, , upgrading weapons!!!') print(' started enter in (i)inventory (c)craft items (d)description of items (m)types of monsters or (f)fight monsters.') print(' enter (help) how game works') print(' enter(?) print again') print(' while in category such (i)inventory press (?) can used go , go category') start_game() main_in = input() level = 0 pxp = 0 gold = 5 monster_lvl = random.randint(1,10) if main_in == ('c'): ws_sticks = 2 ws_stumps = 1 def craft(): print('would craft item??') print('( red = uncraftable )') print('( green = craftable )') print('( type items in lowercase )') if sticks < ws_sticks: puts(colored.red('wooden sword')) else: puts(colored.green('wooden sword')) if stumps < ws_stumps: puts(colored.red('wooden shield')) else: puts(colored.green('wooden shield')) craft() c_item = input() def re_craft(): print('press enter go start screen, or enter c craft an(other) item.') cor_go = input() if cor_go == ('c'): craft() c_item = input() else: game() if c_item == ('no'): print('press enter go start screen') input() game() if c_item == ('wooden sword') , sticks >= ws_sticks: print('wooden sword added inventory') re_craft() if c_item == ('wooden sword') , sticks < ws_sticks: print('you need ' + str(ws_sticks - sticks) + ' stick(s) craft wooden sword') re_craft() if c_item == ('wooden shield') , stumps >= ws_stumps: print('wooden shield added inventory') re_craft() if c_item == ('wooden shield') , stumps < ws_stumps: print('you need' + str(ws_stump - stumps) + ' stumps craft wooden shield.') re_craft() while ('wooden shield added inventory'): w_shield += 1 while ('wooden sword added inventory'): w_sword = +1 if main_in == ('i'): puts(colored.yellow('level: ' + str(level))) puts(colored.yellow('xp: ' + str(pxp))) puts(colored.yellow('gold:' + str(gold))) puts(colored.yellow('items: ' + str(items))) puts(colored.yellow('press enter return start screen')) input() game() if main_in == ('?'): game() game()
now 1 of answers in last question said variable w_sword
, w_shield
should start 1 , variable assignments should outside function: game()
, did said , whenever "crafted" wooden sword or wooden shield showed 1 it. didn't realize no matter crafted (wooden sword or wooden shield) both w_sword
, w_shield
showed 1 when went (i)inventory. instance if type wooden sword
in input known c_item
, go (i)inventory, both w_sword
, w_shield
show 1 though crafted wooden sword.
Comments
Post a Comment