Bytes-like Object?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Elliot Dreemurr
Newbie
Posts: 17
Joined: Fri Aug 13, 2021 5:38 pm
Projects: Only You
Discord: 💙 Elliot/Ellie Dreemurr 💙#2000
Contact:

Bytes-like Object?

#1 Post 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

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Bytes-like Object?

#2 Post 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()
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
r3dhummingbird
Newbie
Posts: 9
Joined: Sat Oct 31, 2020 11:57 am
Completed: Learn to Code RPG https://freecodecamp.itch.io/learn-to-code-rpg
itch: r3dhummingbird
Discord: lynn#9327
Contact:

Re: Bytes-like Object?

#3 Post by r3dhummingbird »

Creator of the project here. The project is https://github.com/RuolinZheng08/renpy-rhythm. Another correct way, as written in the project README, is to add

Code: Select all

define config.open_file_encoding = 'utf-8'
to your options.rpy
Completed Work
Learn to Code RPG: https://freecodecamp.itch.io/learn-to-code-rpg

Post Reply

Who is online

Users browsing this forum: No registered users