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.
-
Megaman Z
- Miko-Class Veteran
- Posts: 829
- Joined: Sun Feb 20, 2005 8:45 pm
- Projects: NaNoRenO 2016, Ren'Py tutorial series
- Location: USA
-
Contact:
#1
Post
by Megaman Z » Mon Jan 19, 2009 8:38 pm
okay, at the risk of spoiling some of the surprise on one of my secret projects, I have a few questions that involve dates, overlays, and date calculations:
1) [answered] what script would I need to use to display a date (not necessarily a real-world (month/day/year) date, but a date nonetheless) at a specific part of the screen (for instance, the top-right corner)?
2) [answered] what python scripting would be the equivalent for this pseudocode?
Code: Select all
int CurrentDay = 1; //initialize this to one
int DisplayDay = 1;
str DisplayMonth = "January"; //day 1 == month 1 or "January"
int DisplayYear = 1; //see above
str Weekday = "Sunday"; // day 1 = sunday - using 7-day week
void GetCurrentDate() {
DisplayDay = CurrentDay % 35;
DisplayMonth = GetMonth(CurrentDay / 35);
Weekday = GetDayOfWeek(CurrentDay);
DisplayYear = (CurrentDay / 140) + 1;
return;
}
str GetDayOfWeek(temp1 as int) {
switch(temp1 % 7){
case == 0 {
return "saturday"; //day 1 == sunday. remember.
}
case == 1 {
return "sunday";
}
// continue like this for case == 2 ~ case == 6
}
str GetMonth(temp1 as int) {
switch(temp1 % 12){
case == 0 {
return "January"
}
// repeat for case == 1 ~ case == 11
}
3) [answered] how do I set a background for the area of the screen the date occupies?
[edit: fixed a typo in the pseudocode]
[edit2: added a third request]
Last edited by
Megaman Z on Tue Jan 20, 2009 8:21 pm, edited 2 times in total.
~Kitsune Zeta
-
chunderbunny
- Regular
- Posts: 52
- Joined: Sat Feb 09, 2008 1:50 pm
- Projects: SSS:Renaissance, Canadense (WIP)
-
Contact:
#2
Post
by chunderbunny » Mon Jan 19, 2009 9:17 pm
This is a straight transliteration of your pseudocode. Personally, I woudln't use globals in GetCurrentDate, but this might be easier depending on the rest of your code. Also I havn't checked the algorithm!
Code: Select all
CurrentDay = 1 #initialize this to one
DisplayDay = 1
DisplayMonth = "January" #day 1 == month 1 or "January"
DisplayYear = 1 #see above
Weekday = "Sunday" # day 1 = sunday - using 7-day week
def GetCurrentDate():
global DisplayDay
global DisplayMonth
global Weekday
global DisplayYear
DisplayDay = CurrentDay % 35
DisplayMonth = GetMonth(CurrentDay / 35)
Weekday = GetDayOfWeek(CurrentDay)
DisplayYear = (CurrentDay / 140) + 1
def GetDayOfWeek(temp1):
case = temp1 % 7
if case == 0:
return "saturday"
elif case == 1:
return "sunday"
elif case == 2:
return "monday"
# continue like this for case == 2 ~ case == 6
def GetMonth(temp1):
case = temp1 % 12
if case == 0:
return "January"
elif case == 1:
return "February"
# repeat for case == 1 ~ case == 11
-
Megaman Z
- Miko-Class Veteran
- Posts: 829
- Joined: Sun Feb 20, 2005 8:45 pm
- Projects: NaNoRenO 2016, Ren'Py tutorial series
- Location: USA
-
Contact:
#3
Post
by Megaman Z » Mon Jan 19, 2009 11:41 pm
I'll run that code through some tests (after a few small adjustments - I can see some bugs would be happening there.)
still leaves #1 kinda... unanswered for me, though.
~Kitsune Zeta
-
JQuartz
- Eileen-Class Veteran
- Posts: 1265
- Joined: Fri Aug 31, 2007 7:02 am
- Projects: 0 completed game. Still haven't made any meaningfully completed games...
-
Contact:
#4
Post
by JQuartz » Tue Jan 20, 2009 12:49 am
Well you can try this:
Code: Select all
init:
$ show_date=None
$ day=None
$ month=None
$ year=None
init python:
def date_show():
if not show_date:
return
ui.text(day+ "/" +month+"/"+year, xpos=1.0, ypos=0.0,xanchor=1.0)
config.overlay_functions.append(date_show)
So everytime you want the date to be shown put values for day, month and year variable (make sure they are string not integers) and show date=True. For example:
Code: Select all
"Today is January 20, 2009"
$ day='20'
$ month='1'
$ year='2008'
$ show_date=True
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.
-
Megaman Z
- Miko-Class Veteran
- Posts: 829
- Joined: Sun Feb 20, 2005 8:45 pm
- Projects: NaNoRenO 2016, Ren'Py tutorial series
- Location: USA
-
Contact:
#5
Post
by Megaman Z » Tue Jan 20, 2009 7:53 am
It took a bit of playing with it, but I got it to work right (thank god I can actually figure out what's going on with the error.txt/traceback.txt files - that actually helps a lot)
the script I ended up with, in case anyone's interested:
Code: Select all
# Control the date and date calculations with regards to the game.
init:
Show_Date = None
CurrentDay = 1 #initialize this to one
DisplayDay = 1
DisplayMonth = "January" #day 1 == month 1 or "January"
DisplayYear = 1 #see above
Weekday = "Sunday" # day 1 = sunday - using 7-day week
python:
def GetDayOfWeek(temp1):
# numbers: 7 = days in week
case = temp1 % 7
if case == 0:
return "Saturday"
elif case == 1:
return "Sunday"
elif case == 2:
return "Monday"
elif case == 3:
return "Tuesday"
elif case == 4:
return "Wednesday"
elif case == 5:
return "Thursday"
elif case == 6:
return "Friday"
def GetMonth(temp1):
# numbers: 35 - days in month
case = (temp1 / 35) % 4
if case == 0:
return "Spring"
elif case == 1:
return "Summer"
elif case == 2:
return "Autumn"
elif case == 3:
return "Winter"
def GetDay(temp1):
# numbers: 35 = days in month
return ((temp1 - 1) % 35) + 1 # subtract one (bugfix - prevent "0" results), then add one to the result.
def GetYear(temp1):
# numbers: 140 = days in year - four months
return (temp1 / 140) + 1
# stuff for display
def date_show():
if not show_date:
return
ui.text("%s, %s %d, %d" % (Weekday, DisplayMonth, DisplayDay, DisplayYear), xpos=1.0, ypos=0.0,xanchor=1.0)
config.overlay_functions.append(date_show)
label Refresh_Day:
# ALWAYS CALL THIS LABEL. always.
$ DisplayDay = GetDay(CurrentDay)
$ DisplayMonth = GetMonth(CurrentDay)
$ Weekday = GetDayOfWeek(CurrentDay)
$ DisplayYear = GetYear(CurrentDay)
$ show_date = true
return
~Kitsune Zeta
-
Megaman Z
- Miko-Class Veteran
- Posts: 829
- Joined: Sun Feb 20, 2005 8:45 pm
- Projects: NaNoRenO 2016, Ren'Py tutorial series
- Location: USA
-
Contact:
#6
Post
by Megaman Z » Tue Jan 20, 2009 5:31 pm
after some more thorough testing, the functionality is there.
the only other thing I would like is to set a background (be it a window or a frame or whatever) for the area occupied by the date so that if I have a bright background with a near-white spot in the top right, the date doesn't "disappear" into the background.
~Kitsune Zeta
-
JQuartz
- Eileen-Class Veteran
- Posts: 1265
- Joined: Fri Aug 31, 2007 7:02 am
- Projects: 0 completed game. Still haven't made any meaningfully completed games...
-
Contact:
#7
Post
by JQuartz » Tue Jan 20, 2009 8:05 pm
I didn't test whether it would work or not but to add window or frame you need to put ui.frame like so:
Code: Select all
# Control the date and date calculations with regards to the game.
init:
Show_Date = None
CurrentDay = 1 #initialize this to one
DisplayDay = 1
DisplayMonth = "January" #day 1 == month 1 or "January"
DisplayYear = 1 #see above
Weekday = "Sunday" # day 1 = sunday - using 7-day week
python:
def GetDayOfWeek(temp1):
# numbers: 7 = days in week
case = temp1 % 7
if case == 0:
return "Saturday"
elif case == 1:
return "Sunday"
elif case == 2:
return "Monday"
elif case == 3:
return "Tuesday"
elif case == 4:
return "Wednesday"
elif case == 5:
return "Thursday"
elif case == 6:
return "Friday"
def GetMonth(temp1):
# numbers: 35 - days in month
case = (temp1 / 35) % 4
if case == 0:
return "Spring"
elif case == 1:
return "Summer"
elif case == 2:
return "Autumn"
elif case == 3:
return "Winter"
def GetDay(temp1):
# numbers: 35 = days in month
return ((temp1 - 1) % 35) + 1 # subtract one (bugfix - prevent "0" results), then add one to the result.
def GetYear(temp1):
# numbers: 140 = days in year - four months
return (temp1 / 140) + 1
# stuff for display
def date_show():
if not show_date:
return
ui.frame(xpos=1.0, ypos=0.0,xanchor=1.0) #Here's the change
ui.text("%s, %s %d, %d" % (Weekday, DisplayMonth, DisplayDay, DisplayYear) )
config.overlay_functions.append(date_show)
label Refresh_Day:
# ALWAYS CALL THIS LABEL. always.
$ DisplayDay = GetDay(CurrentDay)
$ DisplayMonth = GetMonth(CurrentDay)
$ Weekday = GetDayOfWeek(CurrentDay)
$ DisplayYear = GetYear(CurrentDay)
$ show_date = true
return
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.
-
Megaman Z
- Miko-Class Veteran
- Posts: 829
- Joined: Sun Feb 20, 2005 8:45 pm
- Projects: NaNoRenO 2016, Ren'Py tutorial series
- Location: USA
-
Contact:
#8
Post
by Megaman Z » Tue Jan 20, 2009 8:20 pm
that single change works by itself. thanks, JQuartz.
~Kitsune Zeta
-
JQuartz
- Eileen-Class Veteran
- Posts: 1265
- Joined: Fri Aug 31, 2007 7:02 am
- Projects: 0 completed game. Still haven't made any meaningfully completed games...
-
Contact:
#9
Post
by JQuartz » Tue Jan 20, 2009 8:39 pm
Glad that I'm able to help.
I suspect somebody is stealing my internet identity so don't believe everything I tell you via messages. I don't post or send messages anymore so don't believe anything I tell you via messages or posts.
Users browsing this forum: No registered users