- Jun 10, 2017
- 11,016
- 16,300
And you take your diner at... I really need to sleep, I have initially seen 6AM, but it's 6PM. You're not to far from me in fact.I'm from Denmark btw.
And you take your diner at... I really need to sleep, I have initially seen 6AM, but it's 6PM. You're not to far from me in fact.I'm from Denmark btw.
Usually around 6 pm.And you take your diner at... I really need to sleep, I have initially seen 6AM, but it's 6PM. You're not to far from me in fact.
default MomTrust = 0
default MomLust = 0
default NatTrust = 0
default NatTrust = 0
def iLust():
if MomLust > 50:
return 50
return MomLust
def sLust():
return str( iLust() )
def iLust():
if MomLust > 50:
return 50
return MomLust
if NatLust > 50:
return 50
return NatLust
etc ... etc ...
def sLust():
return str( iLust() )
If all the variable names share the same "Nickname of character" + "Lust" structure, you can do this with a single function in place of all theMy question is: Would I need to do this for every variable I've made or is there some more effecient way of doing this?
$ momLust += x
and other $ natLust += x
:init python:
# Change the lust value for any character.
# - who -> Nickname of the character.
# - step -> Value to add to the actual lust ; 1 by default.
def lustChange( who, step=1 ):
# build the name of the variable for this character.
attr = who + "Lust"
# Validate that the variable exist. If not, throw an
# exception to show you your error.
if not hasattr( store, attr ): raise SyntaxError( "Unknown character '{}'".format( who ) )
# Increment the actual value.
value = getattr( store, attr ) + step
# Limit it between 0...
if value < 0: value = 0
# and 50.
if value > 50: value = 50
# And store it back into the variable.
setattr( store, attr, value )
# Define the variable as usual.
default momLust
default natLust
[...]
label blabla:
menu:
"You're beautifull mom.":
# Increase the lust of the mother by 1
$ lustChange( "mom" )
[...]
"Wow, this dress really suit you. It make you look like a goddess.":
# Increase the lust of the mother, but by 2
$ lustChange( "mom", 2 )
[...]
[...]
menu:
"Compliment Nat.":
# Increase the lust for nat by 2
$ lustChange( "nat", 2 )
"Tell her that she look like shit today.":
# Decrease the lust for nat by 5
$ lustChange( "nat", -5 )
"Say nothing.":
[...]
+=
and -=
) by a single function that will change the value, validate that you didn't made a syntax error, and limit the value between 0 and 50.You're welcome.Thank you so much, now I owe you another beer!
def clamp(value,minimum=0,maximum=100):
return min(max(value, min(minimum, maximum)), max(minimum, maximum))
Isn't it a little overkill ? BothPython:def clamp(value,minimum=0,maximum=100): return min(max(value, min(minimum, maximum)), max(minimum, maximum))
min
) or highest (max
) value among the list of values passed in arguments.min( arg1, arg2, *args [, key] )
translate into (I keep outside the optional key argument and the ability to works with string) :val = *args[0]
for x in *args[1:]:
if val < x:
val = x
min
will be interesting, because what's behind is obviously more optimized that this. But when you use it to only have the lowest of two values, you'll still have the equivalent of this iteration. This is useless in this particular case, min( 15, 0)
being translated into :val = 15
for x in ( 0, ):
if val < x:
val = x
def clamp( value, min=0, max=100):
return max if value > max else ( value if value > min else min )
if
structure will be faster than min
or max
:screen whatever:
add myBackground:
xsize ( bgWidth if bgWidth < config.screen_width / 2 else config.screen_width / 2 )
ysize ( bgHeight if bgHeight < config.screen_height / 2 else config.screen_height / 2 )
xalign 0.5 yalign 0.5
def clamp(value,min=0,max=100):
return max if value > ( min if min > max else max ) else value if value > ( max if max < min else min ) else min
min
/max[.icode].
Don't worry, it wasn't a critic. I come from Perl, so I tend to nest many things, especiallyyeah, overkill is my 2nd name and you're absolutely right, your if construct is measured 5-6 times faster but i simply don't like these nested if statements.
if
. But I fully understand that I'm now more a dinosaur than the future of coding