Page 1 of 1

Bytes-like Object?

Posted: Sat Oct 15, 2022 12:04 am
by Elliot Dreemurr
i have no idea what it's trying 2 tell me and can't find anything online about it. please help meee

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 4, in script
    init python:
  File "game/script.rpy", line 4, in script
    init python:
  File "game/script.rpy", line 9, in <module>
    Song('Isolation', 'audio/Isolation.mp3', 'audio/Isolation.beatmap.txt'),
  File "game/00-renpythm/rhythm_game_displayable.rpy", line 178, in __init__
    self.onset_times = read_beatmap_file(beatmap_path)[::beatmap_stride]
  File "game/00-renpythm/rhythm_game_displayable.rpy", line 166, in read_beatmap_file
    onset_times = [float(string) for string in text.split('\n') if string != '']
  File "game/00-renpythm/rhythm_game_displayable.rpy", line 166, in <lambda>
    onset_times = [float(string) for string in text.split('\n') if string != '']
TypeError: a bytes-like object is required, not 'str'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "C:\Users\efabe\Desktop\renpy-8.0.3-sdk\renpy\bootstrap.py", line 277, in bootstrap
    renpy.main.main()
  File "C:\Users\efabe\Desktop\renpy-8.0.3-sdk\renpy\main.py", line 558, in main
    renpy.game.context().run(node)
  File "game/script.rpy", line 4, in script
    init python:
  File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python3.9/site-packages/future/utils/__init__.py", line 441, in raise_
  File "game/script.rpy", line 4, in script
    init python:
  File "C:\Users\efabe\Desktop\renpy-8.0.3-sdk\renpy\ast.py", line 1131, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\efabe\Desktop\renpy-8.0.3-sdk\renpy\python.py", line 1061, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/script.rpy", line 9, in <module>
    Song('Isolation', 'audio/Isolation.mp3', 'audio/Isolation.beatmap.txt'),
  File "game/00-renpythm/rhythm_game_displayable.rpy", line 178, in __init__
    self.onset_times = read_beatmap_file(beatmap_path)[::beatmap_stride]
  File "game/00-renpythm/rhythm_game_displayable.rpy", line 166, in read_beatmap_file
    onset_times = [float(string) for string in text.split('\n') if string != '']
  File "game/00-renpythm/rhythm_game_displayable.rpy", line 166, in <lambda>
    onset_times = [float(string) for string in text.split('\n') if string != '']
TypeError: a bytes-like object is required, not 'str'

Windows-10-10.0.22621 AMD64
Ren'Py 8.0.3.22090809
renpythm 1.0
Fri Oct 14 23:00:23 2022

Code: Select all

init python:

    # register channel
    renpy.music.register_channel(CHANNEL_RHYTHM_GAME)

    import os
    import pygame

    # util func
    def read_beatmap_file(beatmap_path):
        # read newline separated floats
        beatmap_path_full = os.path.join(config.gamedir, beatmap_path)
        with renpy.file(beatmap_path) as f:
            text = f.read()
        onset_times = [float(string) for string in text.split('\n') if string != '']
        return onset_times

Re: Bytes-like Object?

Posted: Wed Oct 19, 2022 1:12 am
by PyTom
Consider setting the encoding for the file:

Code: Select all

        with renpy.open_file(beatmap_path, "utf-8") as f:
            text = f.read()