Need help on this RPG

I’m making a little RPG game, and I don’t know how to make a variable under while True be able to be changed,( I’m trying to make a travel system that changes the player’s location, and “none” is a location where the player starts, and it has no enemies whatsoever, and is under while true, meaning it can’t be changed, but I need to change it.)

while True:
  enemies = {"forest": ["Bear","Wolf","Snake"], "desert": ["Fire Plant", "Scorpion", "Sand Worm"], "mountains": ["Giant Ice Spider", "Polar Bear", "Mammoth"], "none":["none"]}
  location = "none"
  enemy_options = enemies[location]

Easy, put it outside the loop at the beginning of the program, or change it again after the none declaration if you don’t want anything outside the loop

could you elaborate a little more? I’m new.

You can either

location = "none"
while True:
  enemies = {"forest": ["Bear","Wolf","Snake"], "desert": ["Fire Plant", "Scorpion", "Sand Worm"], "mountains": ["Giant Ice Spider", "Polar Bear", "Mammoth"], "none":["none"]}
  enemy_options=enemy[location]
  location = "change it anywhere in this loop if you want"

Or

while True:
  enemies = {"forest": ["Bear","Wolf","Snake"], "desert": ["Fire Plant", "Scorpion", "Sand Worm"], "mountains": ["Giant Ice Spider", "Polar Bear", "Mammoth"], "none":["none"]}
  location = "none"
  enemy_options=enemy[location]
  location = "change me after the location=none in this loop, if you want"

However, the first one is better and less restricted

2 Likes

Thanks! This works for my game!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.