CREATE YOUR AI CUM SLUT ON CANDY.AI TRY FOR FREE
x

RenPy beginner questions

HopesGaming

The Godfather
Game Developer
Dec 21, 2017
1,705
15,377
You can use this:
Code:
if $ day == 20:
     whatyouwannado
or, if you need to specity day night cycle:
Code:
if $ day == 20 and $ time == 1:
     whatyouwannado
Remember to remove the $
If statements do not take Python statements like that.
 
  • Like
Reactions: Porcus Dev

Lyka

Member
Game Developer
Aug 31, 2018
252
377
thank you HopesGaming..

i tried this code before without any functions, i don't get an error.
it just wont trigger.
can it be that it needs a specific place? i was hoping i could write all this events on my event file...
or is my sleepcode the problem?

Code:
            menu:
                "Pay 25 coins?"
                "yes":
                    if money >= 25:
                        $ money -= 25
                        bo "good night"
                        $ day += 1
                        $ time = 0
                        call updatestats from _call_updatestats15
                        jump mainMenu
                    elif money >= 24:
                        $ money +=0
                        bo "you cant afford it!"
                        jump mainMenu
                    elif money == 0:
                        bo "you cant afford it!"
                        jump mainMenu
                    elif day == 20:
                             jump map
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
thank you HopesGaming..

i tried this code before without any functions, i don't get an error.
it just wont trigger.
can it be that it needs a specific place? i was hoping i could write all this events on my event file...
or is my sleepcode the problem?

Code:
            menu:
                "Pay 25 coins?"
                "yes":
                    if money >= 25:
                        $ money -= 25
                        bo "good night"
                        $ day += 1
                        $ time = 0
                        call updatestats from _call_updatestats15
                        jump mainMenu
                    elif money >= 24:
                        $ money +=0
                        bo "you cant afford it!"
                        jump mainMenu
                    elif money == 0:
                        bo "you cant afford it!"
                        jump mainMenu
                    elif day == 20:
                             jump map
Code:
            menu:
                if day == 20:
                          jump map
                else:
                         "Pay 25 coins?"
                         "yes":
                               if money >= 25:
                                    $ money -= 25
                                    bo "good night"
                                    $ day += 1
                                    $ time = 0
                                    call updatestats from _call_updatestats15
                                    jump mainMenu
                               if money >= 24:
                                    bo "you cant afford it!"
                                    jump mainMenu
Put " $ money += 0" isn't necessary, this and putting nothing it's the same.

"if money == 0" is within "if money >= 24" conditional, it isn't necessary to put it separately.

Hope this help.
 
  • Like
Reactions: Lyka

Lyka

Member
Game Developer
Aug 31, 2018
252
377
took me a while to fix some problems.
and yes i invested more work as it was necessary, but im getting better with it.
+=0 was garbage :)

if i try to rent a room with 0 coins:
"if money == 0" without this line the game throws me back to the main menu

but why won't the day == 20 to work as supposed
is it because im in a menu if this event should happen?
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
took me a while to fix some problems.
and yes i invested more work as it was necessary, but im getting better with it.
+=0 was garbage :)

if i try to rent a room with 0 coins:
"if money == 0" without this line the game throws me back to the main menu

but why won't the day == 20 to work as supposed
is it because im in a menu if this event should happen?
I not have the full code to figure what could be the problem, but think to check the variables...when you are in the menu that causes the problem, clic "shift + o" and then write "day", if the returned value isn't 20 you have a value problem, if value is 20 then the problem is in the conditionals or some other code problem.

Had you tried if it fail too with the code I posted above?
 
  • Like
Reactions: Lyka

Epadder

Programmer
Game Developer
Oct 25, 2016
568
1,064
The way the code is set up it will check for every other condition first before it even evaluates what day it is, if any of those conditions are true it will execute the code in that block and then ignore the rest of the menu.

If you want an event to happen just because it is day 20, then you need to check for it in another label. If your going to have multiple things you wish to check depending on the day then you need a label that you go back to every time you 'rest' before returning to whatever label your going to use as a hub.

For example in my project I have :
Code:
##### Python Functions
init python:
    #### Removes 'actions' from the pool a player has
    def worldfunction_ConsumeActionPoints(consumed):
            store.worldstat_ActionsLeft -= consumed
            if store.worldstat_ActionsLeft < 1:
                internalfunction_AdvanceDay()

    #### called when the variable monitor the amount of actions you have is 0 or less.          
    def internalfunction_AdvanceDay():
        store.worldstat_CurrentDay += 1
        store.worldstat_ActionsLeft = store.worldstat_ActionsMaximum
        if store.worldstat_CurrentDay > 7:
            internalfunction_AdvanceWeek()
        else:
            renpy.jump("worldlabel_NewDayBegins")

#### This label is called every day when you run out of 'actions'... time essentially
label worldlabel_NewDayBegins:
    $ uidisplay_WhichBackgroundIsShowing = "base"      
    $ worldfunction_UpdateCurrentDate()
    $ systemfunction_DifficultyUpdate()
    $ uidisplay_WhichBackgroundIsShowing = 1
    $ quick_menu = False
    $ store.rpgstat_PlayerCurrentHealthPool = store.rpgstat_PlayerMaximumHealthPool
    $ uifunction_CustomNotification("You had to return home to rest, a new day begins.")
    if freia.characterstat_CurrentQuestStage == 10000:
        if "hscene_Freia_02" not in freia.characterstat_LabelsOfSexScenesForMemories:
            jump hscene_Freia_02
    jump locationlabel_MainEncampment

   
### The Hub before you explore the world
label locationlabel_MainEncampment:
    $ quick_menu = False
    $ systemfunction_MapMusic()
    $ locationsystem_CurrentLocation = "locationlabel_MainEncampment"
    call screen screenlabel_BaseNavigation
I call worldfunction_ConsumeActionPoints() everytime at the end of a label and I want to advance the day, I simply do:
Code:
label somestoryelement01:
    ### SOME STUFF HAPPENED HERE ###
    $ worldfunction_ConsumeActionPoints(X Amount of Points)
Every time the amount of time in a day is less than the available time I end the day and go to worldlabel_NewDayBegins which I use to run various checks I do every day. I also have Weeks and Years which have separate labels and separate checks.

P.S.
My naming convention is set to keep things very clear about what is going on in every function/label/variable.
 
  • Like
Reactions: Lyka

Lyka

Member
Game Developer
Aug 31, 2018
252
377
Code:
elif result == "bar":
    scene table1
    play music "<loop 6.333>sfx/bar.mp3"
    menu mainMenu:
        "Work 1 shift":
            if time <= 0:
                "it's to early to work"
                jump mainMenu
            elif time >= 3:
                "Bar is closed"
                jump mainMenu
            elif time >=0:
                scene table1
                $ time +=1
                $ money += 30
                call updatestats from _call_updatestats_9
                "you earned 30 coins"
                jump mainMenu
        "Have a drink":
            menu:
                "Pay 5 coins?"
                "yes":
                    if time >= 3:
                        c "Bar is closed"
                        jump mainMenu
                    elif money >=5:
                        $ money -= 5
                        bo "here your drink"
                        c "arg, the good strong stuff"
                        $ time += 1
                        call updatestats from _call_updatestats8
                        jump mainMenu
                    elif money <=4:
                        $ money +=0
                        bo "you cant afford it!"
                        jump mainMenu
                "no":
                        jump mainMenu
        "Rent a Room":
            menu:
                if day == 20:
                     jump map
                else:
                    "Pay 25 coins?"
                    "yes":
                        if money >= 25:
                            $ money -= 25
                            bo "good night"
                            $ day += 1
                            $ time = 0
                            call updatestats from _call_updatestats15
                            jump mainMenu
                        if money >= 24:
                            bo "you cant afford it!"
                            jump mainMenu
                    "no":
                         jump mainMenu
        "Back":
            stop music
            jump map
@mgomez0077 i use now your code in it
right now there is a minor problem with the menu because the line "if day == 20:" expect a menuitem.

just need a coffee to get into gears, then i'm going to tackle this problem

btw i need a diffrent place to get this code running.
here it will only works while i sleep and set time to 1, but if i want to occur it day 21 time 3 don't even now what im doing at this time


@Expander thanks for posting this code. to me it looks like a monster. :) a bit to advanced atm.
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
i use now your code in it (mgomez0077)
right now there is a minor problem with the menu because the line "if day == 20:" expect a menuitem.
Try changing this part:
Code:
       "Rent a Room":
               if day == 20:
                    jump map
               else:
                   menu:
                        "Pay 25 coins?"
                        "yes":
                            if money >= 25:
                                $ money -= 25
                                bo "good night"
                                $ day += 1
                                $ time = 0
                                call updatestats from _call_updatestats15
                                jump mainMenu
                            if money >= 24:
                                bo "you cant afford it!"
                                jump mainMenu
                        "no":
                             jump mainMenu
 
  • Like
Reactions: Lyka

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
btw i need a diffrent place to get this code running.
here it will only works while i sleep and set time to 1, but if i want to occur it day 21 time 3 don't even now what im doing at this time
Then put "if day == 21 and time == 3:" wherever you need
 

Lyka

Member
Game Developer
Aug 31, 2018
252
377
if i use it before rent a room it won't be possible to sleep that day at all.
well, i could jump to an event and end the day in it..
i'll do it like that for now...

thanks for helping me so much!

another question.. i use this code, can i add a color function in here?
textbutton "Inventory" action ToggleScreenVariable("show_inv", True, False)
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
if i use it before rent a room it won't be possible to sleep that day at all.
well, i could jump to an event and end the day in it..
i'll do it like that for now...

thanks for helping me so much!

another question.. i use this code, can i add a color function in here?
textbutton "Inventory" action ToggleScreenVariable("show_inv", True, False)
Well, you can put conditional where you need, for example:
Code:
      "Rent a Room":
                  menu:
                       "Pay 25 coins?"
                       "yes":
                           if money >= 25:
                               $ money -= 25
                               bo "good night"
                               $ day += 1
                               $ time = 0
                               if day == 20:  ## You can put conditional here
                                    jump map
                               call updatestats from _call_updatestats15
                               jump mainMenu
                           if money >= 24:
                               bo "you cant afford it!"
                               jump mainMenu
                       "no":
                            jump mainMenu
If with color function you refer to change text color, I think you can use this:
Code:
textbutton "{color=#ffffff}Inventory{/color}" action ToggleScreenVariable("show_inv", True, False)
 
  • Like
Reactions: Lyka

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,705
I think that perhaps what you need is that textbutton changes in idles/hover states, so if this is want you need, here you have info:


First you need to define style and then set it to your textbutton.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,009
16,295
Took this one, but could have took another one.
Code:
 [...]
                       "yes":
                           if money >= 25:
[...]
                               jump mainMenu
                           if money >= 24:
[...]
                               jump mainMenu
Some words about the construction of condition structures.

With this if then if again, the game will test each condition, and play their part if they are True. It's not a problem when the condition are strict, simple and all mutually exclusives. Note that it's not the case here. You can have both "money >= 25" and the following "money >= 24".
It's also not a problem if each part end by breaking the actual flow of the game ; by a jumping somewhere else, or returning, but not by calling since soon or latter you'll return to the current flow. By example :
Code:
if condition1:
   [...]
   "it was condition 1"
   jump somewhereElse   # beak the actual flow
if condition2:
   [...]
   "it was condition 2"
   call anotherPart    # quit the actual flow, but will return to it
if condition3:
   [...]
   "it was condition 3"
   return                       # break the actual flow by returning to the previous one.
If both condition2 and condition3 are True, then you'll see both "it was condition 2", what is behind anotherPart label, and "it was condition 3".

This structure can be handy when you effectively want that both condition2 and condition3 parts can be played one after the other. But if you want them to be exclusive, even if the conditions themselves aren't, you need to use an if/elif/else instead. By example :
Code:
   "yes":
       if money >= 25:
           "You can afford it"
       elif money >= 20:
           "Almost there, but you're still short of few bucks."
       elif money == 0:
           "Man, you're totally broke, stop dreaming."
       else:
           "You haven't enough money."
       jump mainMenu
This structure is multi conditional. It mean that the game will test if "money >= 25" is True. If it's the case, then it will display "you can afford it" and stop testing. Else, it will try the second condition, then the third, then the default one. But every time it will stop once one condition is True.
So, despite the fact that "money >= 25" and "money >= 20" can be True at the same time, and despite the fact that you don't quit the current game flow, you'll always see only one line. The line corresponding to the first condition to be True.

All this said, I also have some concern as a player. Please, pretty please, if your game is, in a way or another, not fully linear, never hardcode your dates. Same if the game can be continued after the end of the actual content of the main story.
I mean by this that, in these kind of games, you should never use things like :
Code:
  if day == something:
      do something
For you it's clear, the event must happen at this day, and not another one. But the player perhaps have already passed the said day. So, what will happen for him ? You plan an event on day 20, the player is already at day 25, he will never see the event and so be stuck in the game or miss something important.

It's better to use the help of a flag:
Code:
  if day >= something and flagForThisEvent is False:
     do something
So, the event will happen at the expected day, or after it if it don't already happened. This way, it's not a problem that the event was planed for day 20, at day 25 the player will still be able to see it.

I used a Boolean as flag, but if the event is part of a story arc, you can use an integer:
Code:
default storyArc = 0

label something:
  if storyArc == 0 and day >= 5:
      [first event]
      storyArc += 1
  elif storyArc == 1 and day >= 7:
      [second event]
      storyArc += 1
 [...]
  else:
       [nothing more for now]
 
  • Like
Reactions: Lyka and Porcus Dev

Lyka

Member
Game Developer
Aug 31, 2018
252
377
@mgomez0077 about the color.. it was exactly what i was looking for
textbutton "{color=#ffffff}Inventory{/color}"......

thanks for that it really helped alot since i tried to use the color like i define names.

@ that was one thing i was completly mistaken. i thought if i use "if - elif" i can't use "else" anymore,
since my book im reading parallel did only cover "if - else" and "if - elif"

about the game itself: i start linear like a normal visual noval and break it up to let the player do what he want and plan at day 20 a event to get a colar on the player to guide him to some visual noval scenes and then back to free roam.
But its true, its really hard to make it work that it feels natural and not just breaking the flow
 
  • Like
Reactions: Porcus Dev

Lyka

Member
Game Developer
Aug 31, 2018
252
377
I decided i need 2 kind of events:
1. Story events as must have
2. events that a player can miss (like if player visit the shop at day xx, he get oranges for free)

@ since i can't thank you twice...thanks again :) im going to study you post #34 now
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,009
16,295
@ since i can't thank you twice...thanks again :) im going to study you post #34 now
You're welcome, and don't hesitate if you've more questions in the future. Whatever it's me or someone else, there's many people willing to help here.
 
  • Like
Reactions: Lyka and Porcus Dev

Lyka

Member
Game Developer
Aug 31, 2018
252
377
i'm back with the same old question... after working on of other lots of stuff

it's about...

Code:
default storyArc = 0

label something:
  if storyArc == 0 and day >= 5:
     [first event]
     storyArc += 1


default storyArc = 0

label something:
    if storyArc == 0 and day >= 5 and variablex >=6:
        $ storyArc += 1
        jump event
1st: storyArc is a variable and should need a $ or am i wrong here?
2nd: would it be a problem if the "$ storyArc +=1" is before the "jump event" ?
3rd.: i use 2 variables and since i couldn't test it, does it work with 2 "and" (if ... and...and...: )?

and now to my all favorite problem:

how the fu.... can i jump into "label something:" ?
im going nuts right now.

if ihave a location called "PARK" and i go in there i'm in the label park (going to write it here so please ignore tabs)

Code:
label park:
scene park
menu:
"walk around":
$ time += 1
"jump in the water":
[whatever]


BUT HOW DO I GET HERE:


label something:
    if storyArc == 0 and day >= 5 and variablex >=4:
with my current knowlegede i could get it to work if i wrote mostly everywhere "if storyArc == 0 and day >= 5 and variablex >=6:" but that cant be the solution.


sorry but right now i'm getting frustrated, i could get stuff to work i never thought about and i allways get stuck with this particular problem
let me guess there is something like a "check label something" command
 

HopesGaming

The Godfather
Game Developer
Dec 21, 2017
1,705
15,377
default storyArc = 0 do not need the $. It's fine as it is.
storyArc += 1 needs it tho. $ storyArc += 1.
It's not a problem. It actually how it should be.
Yes, you can use "and".

And about your last problem. Are you trying to make a free-roaming style of game? Where you can go to different locations?