Day Counter, Using it, multiple sheets & Python

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.
Post Reply
Message
Author
Eligar
Newbie
Posts: 14
Joined: Thu Apr 24, 2014 11:55 am
Contact:

Day Counter, Using it, multiple sheets & Python

#1 Post by Eligar »

Alright, so I have a couple of questions:

###########################################
################QUESTION 1###############
###########################################


Having spend another good two hours googling, browsing the wiki and just trying to figure this out. I've noticed that I lack the grasp of some of the basic concepts of coding in Ren'py and would love to learn. Upon reading about the currency tutorial on the wiki (http://www.renpy.org/wiki/renpy/doc/coo ... ney_System) I figured that I might also be able to use this bit of code to let the days progress. Simply changing the code from coins to day. So I came up with the following code:

Image

I've made a menu with 3 options. The third option being Rest, which leads to the above mentioned bit of code. Now it's important to mention that throughout the rest of my script there is no reference / labels / declarations or whatever that have to do with the $ day code. Should I have declared it before my labels? (a.i. the same part of your code where you define characters or declare images?)

Error Message:
Image



###########################################
################QUESTION 2###############
###########################################


Once I figured out how the adding days works, how can I then use that data?
Now I found out there's something called an If statement, but I kinda got lost after that.
Say for example I want that on day 7 a dragon flies over and give the player a notification via chat.
Would I then do something like this:

if day = 7:

"You spot a dragon flying over!"



###########################################
################QUESTION 3###############
###########################################


How do I turn my single script.rpy into multiple files? Trying to figure stuff out I broke apart the tutorial that game with the program and noticed how it was split up amongst many diffrent files (.rpy, .rpn, .rpu or whatever) Dumb question I know, but.... how do I add more pages of code to my one project? And how will I know what format to use for what?


###########################################
################QUESTION 4###############
###########################################


Are things like question 1 and 2 Python codes? And if so, do I need to put something special in front of them for them to work? Or can I just type out the bit of code within one of my labels? I read somewhere about an init: command or something. I think a friend tried linking me something that had that at the top, making me think it was required in order to use Python code within your document.


###########################################

I'm sorry if these are really bad questions, but I've been struggling for days. Some solutions I figured out myself, others I got some assistance with. =)
I have a big project planned and having seen a somewhat similair code from another artist got me a little demotivated (because I didn't understand any of it hehe)
However the dedication is there, so I hope someone can help me out! It'll atleast help me one or steps further, before I get stuck again. :roll:

My sincere thanks in advance,

-Eligar

Edit: It's 3 am by this point, please excuse any typo's / grammer.

User avatar
thepiratebei
Newbie
Posts: 11
Joined: Sun Apr 27, 2014 7:38 pm
Projects: Strawberry Jam
Deviantart: thepiratebei
Soundcloud: beikyun
Location: Brazil
Contact:

Re: Day Counter, Using it, multiple sheets & Python

#2 Post by thepiratebei »

Hello friend! I'm rather new to ren'py myself so I'm not sure but I'll be able to help you with the first question. But, try changing the "Day: %(day)" for "Day: [day]", that would make the variable "day" work properly (I think).

As, for the second question, everytime you set an if, ren'py will search for matching results with what you wrote. So if you want something to happen in day seven, you gotta make it search for it.

Also, I'm not sure, but I think you should use == intead of =. Because = is used to set things, like, at the beggining you just said $ days = 0, right? So the program will get confuse if you set another value for it after an if.

I got REALLY confused with the if thing too. But it's basically "If I have 3 apples, I will say x thing. Other than that, I'll say y thing". I always use if and else, cause I think the game needs another way. I mean, it could be any day. So if x thing happens in day 7, WHAT THE FREAK will happen if it's another date? Ren'py will crash almost for sure (always does with me).

So, I'm talking too much here, sorry. Your code should be something like this here

Code: Select all

if day == 7:
    "You spotted a dragon flying over!"
else:
    "Whatever happens if it's not the dragon's day"
 #and here your game goes on"
And for question 3... I have no idea, mate. But I'm sure there are people here that will be able to help :3

(And yes they are python stuff and they are complicated orz BUUUUT those things like days and things that should start counting since the beggining should be placed before the label start)

I hope it helps!!

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Day Counter, Using it, multiple sheets & Python

#3 Post by PyTom »

For question #3 - Ren'Py mostly treats multiple files as one big file. You can jump between the two files without problem.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Eligar
Newbie
Posts: 14
Joined: Thu Apr 24, 2014 11:55 am
Contact:

Re: Day Counter, Using it, multiple sheets & Python

#4 Post by Eligar »

Thanks for the quick reply guys! I did it! I kept getting a message saying: "Say is not defined" eventhough at the start of the script I wrote $ day = 0.
Suddenly I realised it just need a "define" before day = 0.

haha, alright cool, it's a new day. Time to get some coding done!

User avatar
thepiratebei
Newbie
Posts: 11
Joined: Sun Apr 27, 2014 7:38 pm
Projects: Strawberry Jam
Deviantart: thepiratebei
Soundcloud: beikyun
Location: Brazil
Contact:

Re: Day Counter, Using it, multiple sheets & Python

#5 Post by thepiratebei »

Great! Good luck with your game, mate!

User avatar
Showsni
Miko-Class Veteran
Posts: 563
Joined: Tue Jul 24, 2007 12:58 pm
Contact:

Re: Day Counter, Using it, multiple sheets & Python

#6 Post by Showsni »

The code in your first question looks fine (albeit not very useful) apart from the bit at the bottom - I think using either "Day: [day]" or "Day: %(day)d" should work. You need the d on the end to tell the programme that it's an integer, I believe - you'd use s for strings, and so on. Probably easier to just use the square brackets method!

I say it's not very useful because you're setting day to 0 every time you run this bit of code, so it will never move off of 1.

The best place to define this variable (and similar ones) is usually immediately after the start label. That way they will play nicely with saves (if you try to set them in an init block, they won't save properly). You don't need to use define for simply setting a variable.

Code: Select all

label start:
    $ day = 0
Then when you want to use it

Code: Select all

"The day passes."
$ day += 1
"Now it is day [day]."
if day == 7:
    "A dragon flies overhead!"
For question 4, the $ sign means that the rest of the line is python code - you can also put things in a python block:

Code: Select all

$ day = 0
is the same as

Code: Select all

python:
    day = 0
The init thing is a Ren'Py code, it's for stuff that is meant to run every time you start the game. There's also init python for python code. So, if you put something like day = 0 in an init block, it won't be saved properly or participate in rollback, which is why it's better to set up variables after the start label outside of an init block.

Post Reply

Who is online

Users browsing this forum: Lacha