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.
I want to create a function to create new villager in my game if there is enough food. But the game return me UnboundLocalError: local variable 'vllager' referenced before assignment. But I made a villager variable, I don't understand why the game doesn't find it...
default villager = 0
init python:
def creat_villager():
global villager # <--- access the variable
if food >= 10:
villager += 1
Otherwise the function will treat villager as a local variable (one created inside the function), that hasn't been created yet.
A more detailed explanation: viewtopic.php?t=50964#p491426