AVAILABLE_NUMBERS = [1,2,3,4,5,6,7]
def Try():
print('abc')
y = 9
return y
x = 7
Script called Main
from Run import AVAILABLE_NUMBERS
print(AVAILABLE_NUMBERS[0])
from Run import x
print(x)
#Does not work
from Run import y
print(y)
Output:
1
7
Traceback (most recent call last):
File "main.py", line 5, in <module>
from Run import y
ImportError: cannot import name 'y'
exited with non-zero status
Yes I know that, but I forgott to ask if there’s a way to get it out without running it?
I have something like that:
# module
# color cache
import random
#Thank you monster
#--- module level code
'''
This code will be called a single time
when this module gets accessed the first time
'''
# A pseudo constant that defines the initial colors
POSSIBLE_COLORS = [
[0,0,1,True]
, [0,1,0,True]
, [1,0,0,True]
, [255,255,0,True]
, [0.207917,0.105,0.030,True]
, [2.55,0.20,1.47,True]
]
# list
availableColors = list(POSSIBLE_COLORS)
#--- BGE function (argument: controller)
def setRandomColor(controller):
owner = controller.owner
pickedColor = random.choice(availableColors)
availableColors.remove(pickedColor)
owner.color = pickedColor
#Tryed to create variables, but can't output them without running the whole thing - if I do so the random color thing crashes
#define Colors as well as values
def Numberoutput(pickedColor):
pickedColor = setRandomColor(0)
if pickedColor == availableColors[0]:
y = blue
elif pickedColor == availableColors[1]:
y = green
elif pickedColor == availableColors[2]:
y = red
elif pickedColor == availableColors[3]:
y = yellow
elif pickedColor == availableColors[4]:
y = brown
elif pickedColor == availableColors[5]:
y = pink
return y
I’d like to get y out or connect y with the colors. (BGE)
If I have to run the whole thing, the random color choice doesn’t work anymore.