- Sep 26, 2018
- 3,130
- 3,194
how to improve this code character schedule
what I need is able to disable a character and to change a single characters time and for images naming in a number or a pose_name into image name
this a repeat my original post here
what
I have tried what anne O'nymous have posted but it given a error
this code the way it should but there is only one problem is the image
image would named....
mom_bedroom.png
number or a pose_name into image name
mom_bedroom_0.png or mom_bedroom_sleeping.png
I know that I need to add a variable so right now I can have one image per character in a position in a location but can't change the position but can change the location
Hope you understand I'm not great at this the code is below if I can''t get this to work well I do what I did in my other game by using imagebutton with true/false statements
now how does this codes work this will only show one image
images/avatar/mom/mom_sc_Office.png
images/avatar/{pull_the_folders_name_of_character}/{character_name}_{{location}}.png
self.fmt_str = "avatar/{name}/{name}_{{}}.png".format(name=name)
default.rpy
class.rpy
character_screen.rpy
here three images I can't name then this way mom_sc_Office.png now can I
what I need is able to disable a character and to change a single characters time and for images naming in a number or a pose_name into image name
this a repeat my original post here
what
You must be registered to see the links
told me to learn mose Python but can't find nothing on it I don't know if he/she misspelled it or notI have tried what anne O'nymous have posted but it given a error
this code the way it should but there is only one problem is the image
image would named....
mom_bedroom.png
number or a pose_name into image name
mom_bedroom_0.png or mom_bedroom_sleeping.png
I know that I need to add a variable so right now I can have one image per character in a position in a location but can't change the position but can change the location
Hope you understand I'm not great at this the code is below if I can''t get this to work well I do what I did in my other game by using imagebutton with true/false statements
now how does this codes work this will only show one image
images/avatar/mom/mom_sc_Office.png
images/avatar/{pull_the_folders_name_of_character}/{character_name}_{{location}}.png
self.fmt_str = "avatar/{name}/{name}_{{}}.png".format(name=name)
default.rpy
Python:
"""
npc_schedule is a dict { (time: int, location: str): (npc_name: str, lbt: str} }
npcs is a dict { npc_name: NPC } used to get an NPC by its name.
"""
default npc_schedule = {}
default npcs = {}
default time = 0 #when this is change the character will change
label Characters_Variables:
# (time, "location"): "lbt"
$ NPC.create("mom", nice_name="Mom", schedule={
(0, "sc_Office"): "test", #sleeping #this will be a problem is at
(1, "sc_Office"): "test", #changing #this will be a problem is at
(2, "sc_Office"): "test", #looking out the window #this will be a problem is at
(3, "sc_Office"): "test", #watching tv
})
Python:
init python:
class NPC:
@classmethod
def create(cls, name, nice_name, schedule):
"""
schedule: a dict {(time: int, location: str): lbt: str}
value will be converted to tuple (name, lbt) during creation
"""
npcs[name] = NPC(name, nice_name, NPC.__key)
for key, value in schedule.iteritems():
if key not in npc_schedule:
npc_schedule[key] = [ ]
npc_schedule[key].append( (name, value) )
__key = object() # To disallow accidental creation
def __init__(self, name, nice_name, key):
assert(create_key == NPC.__key)
self.nice_name = nice_name
self.fmt_str = "avatar/{name}/{name}_{{}}.png".format(name=name)
@property
def avatar(self):
global location
avtr = self.fmt_str.format(location)
if renpy.loadable(avtr):
return avtr
class School(object):
def __init__(self, name, unlocked):
self.name = name
self.unlocked = unlocked
sch = []
sch.append(School("sc_Hallway", True))
sch.append(School("sc_Classroom 1", True))
sch.append(School("sc_Classroom 2", True))
sch.append(School("sc_Classroom 3", True))
sch.append(School("sc_Bathroom", True))
sch.append(School("sc_Gym", True))
sch.append(School("sc_Pool", True))
sch.append(School("sc_shower", True))
sch.append(School("sc_Office", True))
location = sch[7].name
Python:
screen character_screen():
$ npc_present = npc_schedule.get( (time, location), [ ] )
for name, lbt in npc_present:
$ npc = npcs[name]
imagebutton:
idle npc.avatar
hover npc.avatar
focus_mask True
action Call(lbt) #calls labels
Last edited: