How to reset a variable ?

MisterMaya

Member
Game Developer
Apr 25, 2021
396
1,931
Hi, I'm new to renpy and i've been trying to make something like this work :

if daytime >= 5:
$ daytime == 1

the thing is, I have 4 periods which are basically morning, afternoon, evening, night, and i want to make sure that when you're at night and you skip ( I made a button that adds 1 to daytime everytime you press it) to next day, it resets to daytime = 1 and not daytime = 5.

Any suggestions ?
 

sillyrobot

Engaged Member
Apr 22, 2019
2,159
1,879
Double equals sign is a comparison -- is daytime equal to 1, yes or no? Assignment requires a single equals sign.
$ daytime = 1
 

MisterMaya

Member
Game Developer
Apr 25, 2021
396
1,931
I've tried it to, but it didn't work ...

if daytime >= 5:
$ daytime = 1 i tried this
 

sillyrobot

Engaged Member
Apr 22, 2019
2,159
1,879
Can you post a bit more of the code? Put ]code[ and ]/code[ around it to protect the formatting. (I've deliberately reversed the brackets so it'll show up as text -- put them right way around in your post).
 

MisterMaya

Member
Game Developer
Apr 25, 2021
396
1,931
Yes thank you,

Here's my code :

Code:
default daytime = 1
    $ dayweek = 1
    default maxdaytime = 5

imagebutton:
        xpos 40
        ypos 10
        at custom_zoom2
        idle "skip.png"
        action Jump("Daytime")

label Daytime:

    $ daytime += 1
    call screen locations
    if daytime >= maxdaytime:
        $ daytime = 1

What happens basically is the skip button is only available on the "screen locations".
so everytime i press it, it adds +1 to daytime and goesback to "screen locations".
I have a series of menu to check wether the daytime is back to 1 but everytime it doesn't work.
 

MisterMaya

Member
Game Developer
Apr 25, 2021
396
1,931
Omg I've just figured it out ... XD

I just need to invert two lines so instead of being this :

Code:
label Daytime:

    $ daytime += 1
    call screen locations
    if daytime >= maxdaytime:
        $ daytime = 1
It looks like this

Code:
$ daytime += 1
    if daytime >= maxdaytime:
        $ daytime = 1
    call screen locations
So sorry for wasting your time lol
 
  • Like
Reactions: sillyrobot

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,963
16,202
Here's my code :
Python:
label Daytime:

    $ daytime += 1
    call screen locations   # <--- Here
    if daytime >= maxdaytime:
        $ daytime = 1
How do you want it to works, your if is never proceeded.

  1. You goes to "Daytime" label ;
  2. The time is advanced ;
  3. You're sent back to the "locations" screen ;
  4. It loop with 1).

Do this and it will works :
Python:
label Daytime:

    $ daytime += 1
    if daytime >= maxdaytime:
        $ daytime = 1
    call screen locations
Edit: Well, you beat me into finding your mistake.
 

sillyrobot

Engaged Member
Apr 22, 2019
2,159
1,879
I don't think you can ever reach your if that reset it. You add 1 then go back to the screen. Move the if above the call.
 
  • Like
Reactions: MisterMaya

MisterMaya

Member
Game Developer
Apr 25, 2021
396
1,931
Python:
label Daytime:

    $ daytime += 1
    call screen locations   # <--- Here
    if daytime >= maxdaytime:
        $ daytime = 1
How do you want it to works, your if is never proceeded.

  1. You goes to "Daytime" label ;
  2. The time is advanced ;
  3. You're sent back to the "locations" screen ;
  4. It loop with 1).

Do this and it will works :
Python:
label Daytime:

    $ daytime += 1
    if daytime >= maxdaytime:
        $ daytime = 1
    call screen locations
Edit: Well, you beat me into finding your mistake.
Thanks anyway dude !