I have a few closely related question about variable definition. I must say, I'm completely lost.
1- First thing first, from previous programming experience, I have the reflex of trying to define every variable before the start label. Also, I tend to give them the right type, for example, I will set a variable that will serve as a float as a float (a=0.0), an array as an empty array (a=[]) and a string as an empty string (a="")
Is this something that help/ is recommended/ is needed?
2-I'm not sure I define my variable the right way. Here a few example from my most recent script. I will also include some function, as it will be pertinent for a later question:
Code: Select all
init python in chara:
#Fix
name = "Pholder"
#Physical
muscle=5.0
fat=5.0
cardio=5.0
HP=10.0
def dayend():
#Physical
global muscle
global fat
global cardio
global HP
HP=HP+1-fat/10.0+muscle/5.0+cardio/5.0
if HP>50:
HP=50.0
return
def add(variable,value):
#Physical
global muscle
global fat
global cardio
global HP
#physical
if variable == "muscle":
if (muscle>1)&(cardio>0):
muscle=muscle+value/10.0*cardio/muscle
else:
muscle=muscle+value
if muscle>10:
muscle=10.0
elif muslce<0:
muscle=0
return
elif variable== "fat":
if value>0:
fat=fat+value/cardio/10.0
if fat>10:
fat=10.0
elif value<0:
fat=fat+value/10.0*(cardio+1)/10.0
if fat<0:
fat=0
return
elif variable== "cardio":
cardio=cardio+variable/10.0
if cardio>10:
cardio=10.0
elif cardio<0:
cardio=0
return
elif variable== "HP":
HP=HP+value
if HP>50:
HP=50
elif HP<=0:
renpy.jump("game_over")
return
define mnt=[None,
_("January"),_("February"),_("March"),_("April"),
_("May"),_("June"),_("July"),_("August"),
_("September"),_("October"),_("November"),_("December")]
default mlen=[None,
31,30,31,
30,30,31,
31,30,31,
30,30,31]
label game_over:
nvl clear
"You're dead"
return
Next is the define mnt statement. This is an array I use to determine what to write for the month in the date on my status screen. I've used define because, from what I understood, you shouldn't change a variable set with define.
To finish, I've used default to define the mlen array, representing month length because I want to cut a day to February when the year isn't a leap year, as it is the first year of the game.
I should also add that, as of now, it works, and all relevant variable seems to save (I haven't done extended testing yet.), even if my search indicate that it shouldn't (Manual on python init block). Also, the chara initialization is in a separated .rpy file from the script.
Can I do that (should it work?) and will that still work with ren'py 6.99.14?
3-Is there a way to discardd variable that arn't usefull anymore, as to liberate space in the save file/memory? For exemple, there is no need to keep in memory the answer at the start of the game that would influence only two line a bit later in the same section. If there is a way, should I do it? If not, should I try to always reuse the same variable in all situation? (Eg. I don't need a variable "salad" to note a character choice for lunch. I could use the same variable as the one I would use later on to remember if they want to play soccer or tennis.)
4-It is a bit unrelated, but is there a way to use more complex function, such as exponential and logarithm? I would like to use some to scale the previously mentioned chara variables.
5-A yet less related question, but with the search engine down, I'm a bit too shy to post 4 new topic in the same category in less than a day. So, I would like to end the game after the label game_over is reached, but as I use many call to label in the script, as of now I end up just going back to the middle of the story.
In conclusion, sorry for the long post and the numerous question, but with the search engine down, it was the or multiple post, and I believe this to be the lesser evil. If I'm wrong, you can tell me and I will edit the post in consequence.
Thanks in advance for your help