Tried Importing Name from File1 to File 2 so it can be used in Char1 creation but error as it state index out of range Any ideas how can i get the name and roles from file 1 and input it in file 2 ?
Tested with File 1 that the name i input will get saved in the Name List when i tried printing it out but when i shift it over to File 2 its an empty list
File 1:
import pygame
import pygame_menu
import play
import PSB_Game
import random
Roles = [['WARRIOR'], ['TANK']]
Name = []
S_Role = []
def get_name(name):
Name.append(name)
print("my name is", name)
print(Name)
def get_role(role):
S_Role.append(role)
print('role is',role)
print(S_Role)
def main():
pygame.init()
surface = pygame.display.set_mode((800, 550))
menu = pygame_menu.Menu('Welcome', 800, 550, theme=pygame_menu.themes.THEME_BLUE)
menu.add.text_input('Character 1 Name:', onreturn= get_name)
menu.add.dropselect('Role:', Roles, onchange= get_role)
menu.mainloop(surface)
pass
if __name__ == "__main__":
main()
File 2:
import PlayerCreate
def main():
Char1 = warrior(200, 260, PlayerCreate.Name[0], 100, 5, 3, 'Warrior')
Char1_health_bar = HealthBar(100, screen_height - bottom_panel + 40, Char1.hp, Char1.max_hp)
run = True
while run:
clock.tick(fps)
#draw background
draw_bg()
#draw_panel
draw_panel()
Char1_health_bar.draw(Char1.hp)
#draw warrior
Char1.update()
Char1.draw()
#player action
if Char1.alive == True:
if current_Warrior == 1:
action_cooldown += 1
if action_cooldown >= action_wait_time:
#look for player action
# #attack
Char1.attack(Warrior1)
current_Warrior += 1
action_cooldown = 0
wanted to create a turn based battle game with the input for user for the char name and print them out