简体   繁体   中英

int() argument must be a string, a bytes-like object or a number, not 'list' Python python-tcod Roguelike

I am making a roguelike game using the python-tocd roguelike engine. My game is based off the python libtcod roguelike tutorial.

I'm making a list of constants that I use to generate maps

game_map.make_map(constants['max_rooms'], constants['room_min_size'], constants['room_max_size'],
                  constants['map_width'], constants['map_height'],entities,player,
                  constants['maze_min_size'], constants['max_maze_rooms'], ['maze_max_size'])

Now i'm using some code in a function to determine the size of the room.

for r in range(max_rooms):
    # random width and height
    w = randint(room_max_size, room_min_size)
    h = randint(room_max_size, room_min_size)

    # random position without going out of the boundaries of the map
    x = randint(0, map_width - w - 1)
    y = randint(0, map_height - h - 1)

I've defined the variables here

map_width = 80
map_height = 45

room_max_size = 10
room_min_size = 6
max_rooms = 30

Now when I start up the game this appears?

  File "C:/Users/Al Abraham/Documents/CaveRL/CaveRL/engine.py", line 466, in <module>
    main()
  File "C:/Users/Al Abraham/Documents/CaveRL/CaveRL/engine.py", line 445, in main
    player, entities, game_map, message_log, game_state, ggender = get_game_variables(constants)
  File "C:\Users\Al Abraham\Documents\CaveRL\CaveRL\initialize_new_game.py", line 115, in get_game_variables
    constants['maze_min_size'], constants['max_maze_rooms'], ['maze_max_size'])
  File "C:\Users\Al Abraham\Documents\CaveRL\CaveRL\map_objects\game_map.py", line 110, in make_map
    w = randint(room_max_size, room_min_size)
  File "C:\Python37\lib\random.py", line 222, in randint
    return self.randrange(a, b+1)
  File "C:\Python37\lib\random.py", line 184, in randrange
    istart = _int(start)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'

What should I do?

When you use the int() function, you must have a string, or some number. What this error says is that at least one of your parameters is a list, not a number.

You should check the line where you declare the "w" variable, it seems that the source of trouble is either from room_max_size or room_min_size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM