Okay, I'll explain. The error is because your variables have not been initialised.
That is the only cause of this error.
The solution is to initialise the variables.
That is what the code I have given you does.
Without more information nobody can help because the error is caused by not initialising variables, so saying you initialised the variables and you're still getting the error doesn't help, because the error exists because you didn't initialise the variables.
You need to initialise the variables.
That is all you need to do.
Initialise the variables.
Once you initialise the variables this problem will go away, because it is caused by not initialising the variables and not something else.
Initialising variables is easy.
All you need to do is set them to something before you use them.
Before you check the value of Monday in an 'if' statement, set Monday to something.
It can be False.
It can be True.
However, it needs to be set to something.
You must also make sure that when you set Monday to something, you do this before 'label morning' is run.
If 'label morning' is run in the middle of the game, not during init, this is easy because putting it after 'label start:' will ensure it is run.
You could also do it in an 'init' block but this is not ideal because then your variables will not be tracked by rollback until they appear for the first time, which will cause problems with saving and loading.
However, this will at least stop this error from occurring.
Initialise the variables.
The error you got, "NameError: name 'Monday' is not defined" says that ren'py doesn't know what 'Monday' is.
This can be fixed by setting 'Monday' to something before you check it.
For example, this will give an error:
Code: Select all
label start:
if Monday == True:
"It's Monday!"
return
But this won't give an error:
Code: Select all
label start:
$Monday = True
if Monday == True:
"It's Monday!"
return
This is because, in the first case, Monday has not been defined before it is first seen.
In the second case, Monday has been defined.
This does not mean you want Monday to be set to True (or False) when you run 'morning', because this code is intended to advance the current day.
This means you need to define Monday and set it to something before this code is ever run.
Somewhere after 'label start:' is ideal, because it means the current week will be reset every time.
By the way, variable names are case-sensitive.
If you are setting the variable 'monday' and then checking the variable 'Monday' that will not work.
You must also not first set 'Monday' inside a python function.
In other words, if you are doing this:
Code: Select all
init python:
def InitialiseWeek():
Monday = False
label start:
$InitialiseWeek()
...that will _not_ work, because InitialiseWeek gets its own scope.
By the way, 'define' would also work, but this is not recommended as it's got the same problems as initialising the variables within an init block.
So, while this will get rid of your error:
it will have the same problems, so it's not really recommended.
If you're having trouble getting stuff to run early enough and putting it after 'label start:' isn't working, you could always put it in a start_callback. This ensures it will be run before 'label start' and anything like that:
Code: Select all
init python:
def InitialiseWeek():
renpy.store.Monday = False
renpy.store.Tuesday = False
renpy.store.Wednesday = False
renpy.store.Thursday = False
renpy.store.Friday = False
renpy.store.Saturday = False
renpy.store.Sunday = False
config.start_callbacks.append(InitialiseWeek)
Now, if that still doesn't work, the issue is that 'label morning' is being run during init, which of course won't work.
But either way, that is the only issue with this code: 'Monday' is not being declared before use.
You need to set it to something before checking what it is set to.
That is the only issue. When fixed, that error will disappear.
Now, I go into this in excruciating detail because this is a common issue with your posts.
You post that you have a problem with something, there's a bug in your code.
Someone gives a solution.
You then post that it doesn't work.
There's no new information.
Often, the solution is _the_ solution to the problem you have.
Like with initialising variables- the uninitialised variable error can be eliminated by initialising variables.
There isn't another solution to the problem.
So if you just post that it doesn't work, without giving more information, nobody can help you. We can't see your code. We can sort of imagine hypotheticals that you could possibly have- maybe after initialising the day variables, you then go and delete them all, but the chances of actually working out what you did are random at best. You could just post your entire project every time you have a problem, but it's more efficient for you and for us if you posted the problem area and gave sufficient information to enable us to solve it. In the case of this, posting all your code would probably be easiest.