
지속데이터를 삭제하고 만들던 프로젝트를 실행하자,
렌파이에서 screen.rpy의 init python으로 작성된 파이썬 블록 오류가 났다.
TypeError: 'NoneType' object is not iterable
ㅤ
init python:
try:
info_person_count = 0
info_person_total = 0
info_extra_count = 0
info_extra_total = 0
for ach_word in persistent.achievements_dict:
if persistent.achievements_dict[ach_word]["category"] == 0:
info_person_total += 1
if achievement.has(ach_word):
if persistent.achievements_dict[ach_word]["category"] == 0:
info_person_count += 1
info_person_achs = str(info_person_count) + "/" + str(info_person_total)
for ach_word in persistent.achievements_dict:
if persistent.achievements_dict[ach_word]["category"] == 1:
info_extra_total += 1
if achievement.has(ach_word):
if persistent.achievements_dict[ach_word]["category"] == 1:
info_extra_count += 1
info_extra_achs = str(info_extra_count) + "/" + str(info_extra_total)
except:
info_person_achs = ""
info_extra_achs = ""
이 코드는 오류 처리를 위해 임의로 try-except 문에 포함시킨 상태다.
ㅤ
렌파이 위키 참조: https://www.renpy.org/doc/html/persistent.html
The persistent object is special in that an access to an undefined field will have a None value, rather than causing an exception. If something other than None is to be the default of a persistent value, the default statement should be used:
default persistent.main_background = "princess_not_saved"
persistent 개체는 정의되지 않은 필드에 대한 액세스가 예외를 일으키지 않는 대신, None 값을 갖는다는 점에서 특별합니다. None 이외의 값이 영구적 값의 기본값이 될 경우 default 문을 사용해야 합니다.
persistent data는 default 값을 따로 지정하지 않으면 초기에 'None' 값을 갖는다. persistent.achievemets_dict는 achievement.rpy 파일에 다음과 같이 선언되어 있다.
init python:
# Define your achievements here
persistent.achievements_dict = { "leewan": {"type": 0,
"category": 0,
"title": "인물정보 '총리대신'",
"title_": "총리대신",
"text": "총리대신 이완은 고종을 손바닥 위에 올려놓고 좌지우지하는 인물이다. 갑신정변 당시 김옥균에 의해 제거될 뻔했으나, 청군을 끌어들여 김옥균을 몰아내고 살아남았다."
},
"coffee": {"type": 0,
"category": 1,
"title": "잡학정보 '가비'",
"title_": "가비",
"text": "커피. 고종은 외국에서 들여온 커피를 즐겨 마셨다. 심지어는 와플까지 즐겼을 정도로 서양문물, 특히 먹을거리에 진심이었다."
}
}
persistent.profile_items = { "ending1" : "엔딩 1: 너무나 많이 무엄한 죄",
"ending2" : "엔딩 2: 거짓말이야",
"ending3" : "엔딩 3: 아첨은 그만",
"ending4" : "엔딩 4: 효자 정훈"
}
ㅤ
단순히 achievements_dict를 정의하는 부분 앞에 default를 붙이면 될 것이라 생각했다.
init python:
# Define your achievements here
default persistent.achievements_dict = { "leewan": {"type": 0,
"category": 0,
"title": "인물정보 '총리대신'",
"title_": "총리대신",
"text": "총리대신 이완은 고종을 손바닥 위에 올려놓고 좌지우지하는 인물이다. 갑신정변 당시 김옥균에 의해 제거될 뻔했으나, 청군을 끌어들여 김옥균을 몰아내고 살아남았다."
},
"coffee": {"type": 0,
"category": 1,
"title": "잡학정보 '가비'",
"title_": "가비",
"text": "커피. 고종은 외국에서 들여온 커피를 즐겨 마셨다. 심지어는 와플까지 즐겼을 정도로 서양문물, 특히 먹을거리에 진심이었다."
}
}
default persistent.profile_items = { "ending1" : "엔딩 1: 너무나 많이 무엄한 죄",
"ending2" : "엔딩 2: 거짓말이야",
"ending3" : "엔딩 3: 아첨은 그만",
"ending4" : "엔딩 4: 효자 정훈"
}
그런데, invaild syntax 오류가 발생했다.
default p -> ersistent.achievemets_dict
invalid syntax default persistent"leewan": {"type": 0, ^ Ren'Py Version: Ren'Py 8.0.3.22090809 Sun Mar 5 09:47:25 2023 ```
default를 붙이면 screen.rpy의 init python 블록 내에서는 인식이 잘 된다.
대신 achievemnt.rpy의 init python 블록 내에서 default 문이 인식이 되지 않아 오류가 난다.
하나를 해결하면 다른 하나가 문제인 상황이었다.
ㅤ
screen person_info():
$ info_person_count = 0
$ info_person_total = 0
for ach_word in persistent.achievements_dict:
if persistent.achievements_dict[ach_word]["category"] == 0:
$ info_person_total += 1
if achievement.has(ach_word):
if persistent.achievements_dict[ach_word]["category"] == 0:
$ info_person_count += 1
$ info_person_achs = str(info_person_count) + "/" + str(info_person_total)
screen extra_info():
$ info_extra_count = 0
$ info_extra_total = 0
for ach_word in persistent.achievements_dict:
if persistent.achievements_dict[ach_word]["category"] == 1:
$ info_extra_total += 1
if achievement.has(ach_word):
if persistent.achievements_dict[ach_word]["category"] == 1:
$ info_extra_count += 1
$ info_extra_achs = str(info_extra_count) + "/" + str(info_extra_total)
init python 블록이 문제가 되면, screen 블록 안에 $를 붙이고 파이썬 구문을 추가해 주면 된다.
ㅤ
'NoneType' object is not iterable 오류는 이해가 가지만 왜 invalid syntax 오류가 나는지 이해는 가지 않는다. 하지만 이미 정의된 persistent 데이터가 있는 이상, default가 아니더래도 screen 문 안에 포함되면 접속이 가능한 것 같다. 이가 없으면 잇몸으로라도 해결하자는 주의라 우선 조치는 이렇게 해 두었고, 기회가 되면 invalid syntax error의 원인을 알아볼 것이다.