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.
I'm trying to write a piece of code that increments a value in desire_list by the amount contained in exposure_list, and then wipe exposure_list clean to be used again the next day. However, I never want any single desire_list value to go above 5(while also being able to raise the minimum above 0 if I choose), AND I don't want the total of desire_lists values to go above, say, 10. Is this possible or am I dreaming? The below code works for me, I just can't work out how to limit the values.
You likely just want python min( *args ) and max( *args ), maybe with some list comprehension (or just iterate indices in a for or while loop as you are doing)
I've edited the code a bit, having been unable to make the above suggestions work for me. This allows me to set a max value of 10 for the whole set of data, a max of 5 for any individual value but will still reset each value down to 0 instead of a minimum individual value.
while sum(desire_list) < 10 and sum(exposure_list) >0 and i < len(exposure_list):
$ desire_list[i] += exposure_list[i]
while sum(desire_list) >10:
$ desire_list[i] -= 1
if desire_list[i] >5:
$ desire_list[i] = 5
$ exposure_list[i] = 0
$ i += 1
It's not perfect, but it will do for now. To answer Belgerum's "question" I really want to be able to set a simple max value to cover the sum of desire_list, and a max value of 5 for each value of the desire_list(as I have been able to do in the dodgy code above.
However I want to be able to 'decay' the desire values over time down to a minimum value that can change over time. Something like this:
$ i = 0
while i < len(desire_days):
if day > desire_days[i] and if desire_list[i] > min_list[i]:
$ desire_list[i] -= 1
$ i += 1
This part checks to see if a the subject has been exposed to each activity in the past 7 days and if the desire value is higher than the minimum then decays the value of the desire by one if it meets the conditions.
$ i = 0
while sum(desire_list) < 10 and sum(exposure_list) >0 and i < len(exposure_list):
$ desire_list[i] += exposure_list[i]
$ desire_days[i] = day + 7
while sum(desire_list) >10:
$ desire_list[i] -= 1
if desire_list[i] >5:
$ desire_list[i] = 5
$ exposure_list[i] = 0
$ i += 1
$ day += 1
This is much the same as before. I've checked, and each variable increases as expected, the maximums cannot be exceeded and the minimums remain above 0 on an individual basis as defined by min_list.