Changing other variables inside a class
Posted: Sat Dec 07, 2019 9:59 pm
Hello Everyone. I tried to find the answer on my own, but I didn't see what I was looking for. Or maybe I didn't use the right keywords.
tl;dr: Can you change an unrelated variable inside another class?
Anyway, in my game, I want Characters to be in different locations at different times of the day. But I want there to be a sort of weighted system, as well. Person A isn't ALWAYS in the Bathroom in the morning, for example. But when she IS in the bathroom, she isn't anywhere else, if that makes sense.
That is easy enough to call once or twice with
But I have quite a few characters. And any number of them could be in any number of places. So the code gets exponentially longer with more people/places.
That is further compounded by time. I am using a class I saw here a while ago for time/date stuff.
In my situation, I want the character's locations to change based on a weighted value every time the game updates into a new "period" (Morning, Afternoon, Night, blah blah). But I can't seem to get things to work out for me. If I change "update" to include something easy like this:
Nothing changes. The value itself doesn't change, and a will stay in the bathroom (poor girl). I don't know if you can affect outside variables INSIDE a class... And I'm having a dickens of a time with the cookbook finding the right info.
I'm also trying to figure out a more elegant way of dealing with the weighted nature of the character's schedules. instead of using renpy.random.randInt for everything.
Does anyone have any input? Or maybe push me in the right direction? Right place to look and all that?
Thank you so much!
Good vibes out,
EchoEcho
tl;dr: Can you change an unrelated variable inside another class?
Anyway, in my game, I want Characters to be in different locations at different times of the day. But I want there to be a sort of weighted system, as well. Person A isn't ALWAYS in the Bathroom in the morning, for example. But when she IS in the bathroom, she isn't anywhere else, if that makes sense.
That is easy enough to call once or twice with
Code: Select all
$ d20 = renpy.random.randInt (1,20)
if d20 > 10:
$ aLoc = "bathroom"
else:
$ aLoc = "somewhere else"
That is further compounded by time. I am using a class I saw here a while ago for time/date stuff.
Code: Select all
class gameTime:
gamePeriods = ("Early Morning","Morning","Late Morning","Afternoon","Midday","Evening","Night","Late Night")
def __init__(self):
self.now = 0
self.hours = 12
self.day = 1
self.periodCount = 0
self.timeSlept = 0
def tAdvance(self, n=1):
self.hours += n
self.periodCount += n
if self.hours >= 24:
self.hours -= 24
self.day += 1
day = self.day
while self.periodCount >= 3:
self.advance()
self.periodCount -= 3
def advance(self, n=1):
self.now += n
self.update()
def sleepMorning(self):
self.timeSlept = 1
self.tAdvance()
while self.hours != 6:
self.tAdvance()
self.timeSlept += 1
def hoursSlept(self):
return self.timeSlept
def period(self):
return gameTime.gamePeriods[self.now % len(gameTime.gamePeriods)]
def update(self):
if self.now >= len(gameTime.gamePeriods):
self.now -= 8
def date(self):
return str(self.day)
def getHours(self):
return str(self.hours)
def tSet(self, n=1):
self.timeSlept = 1
while self.hours != n:
self.tAdvance()
self.timeSlept +=1Code: Select all
default aLoc = "bathroom"
class gameTime:
(...rest of the time class)
def update(self):
aLoc = "kitchen"
if self.now >= len(gameTime.gamePeriods):
self.now -= 8
(... rest of the time class)
label start:
$ g_time = gameTime()
$g_time.tAdvance(12)
a "I am in the [aLoc]!"
I'm also trying to figure out a more elegant way of dealing with the weighted nature of the character's schedules. instead of using renpy.random.randInt for everything.
Does anyone have any input? Or maybe push me in the right direction? Right place to look and all that?
Thank you so much!
Good vibes out,
EchoEcho
