game engine - Calling a variable outside of a function in python? -
I know that hundreds have been asked before, but I am able to get answers directly from the other questions. do not think so . I need a simple explanation how can I call a variable that was defined somewhere inside the script and inside the function outside of that function. Here's the first script:
# Combat Engine Alpha Step # Personal Character Statistics, Strength, Speed, Dexterity, Stir, Experience, Strength, Composition of Levels 1-6 # Shimot Stats Strength 1, Speed 2, Dexterity3, STR4, Experience 5, Power 6SamostStats = (3, 3, 3, 3, 5, 5) #Crepsiac statistics cryptasats = (6, 1, 2, 3, 4, 4) Import time DEF (): Ask = Int (Input ("Do you want to play as Cripescum (1) or Samoth (2)?") Ask if == 1: Prints ("Cripissimum: Strength -", Creepskastats [0], "Speed-", CrepuscStats [1], "Dexterity -", Crypt Stats [2], "STIR -", Crapsstats [3], "Experience -", 4], ask "power -", crapscustats [5]) = intestine (input ("Is this your character? Yes (1) no (2)")) if askOK == 1: char = 1 import field elif askOK == 2: askChar () elif askChar == 2: print ("Samoht: Strength -", samohtStats [0], "speed -", samohtStats [1], "dexterity -", samohtStats [2], " SamohtStats [3], "Experience -", samohtStats [4], "Power -", samohtStats [5]) askOK = int (Input ("What There is your character? Yes (1) No (2) ")) If askOK == 1: Char = 2 Import Area elif askOK == 2: askChar () Print (" Welcome to TNS: Arena! (Alpha) ") askChar () Then I'm importing the file "Region":
#arena script if char == 1: print ("test") time.sleep (3) elif char == 2: print ("test") time.sleep (3) As you can see, I'm importing another file and after that I am trying to use the local function outside my function. I do not know that this is a problem. My problem To go about fixing, I need simple explanations just as the correct syntax.
When you import area [if it goes away], you should become a name eerr that there is no name char . When you import a module into Python, by doing the import field , you are creating a name, field within the import statement, Within import, in the code field will be available if you import it into the global scope, it will be global. Name field will reference a module object Note that module is just another Python object type is module object Features are global in the source code of that module. If you char inside arena.py , then define the import field the global name of your main file In the location, you can then refer to as char as arena.char .
Comments
Post a Comment