Forum Discussion
9 years ago
"IngeJones;15205732" wrote:
Hmm ok I will give this one more chance. I wrote the code as:
def assign_bassinet_for_baby(sim_info, ignore_daycare=False):
object_manager = services.object_manager()
for bassinet in object_manager.get_objects_of_type_gen(*BabyTuning.BABY_BASSINET_DEFINITION_MAP.values()):
while not bassinet.transient:
set_baby_sim_info_with_switch_id(bassinet, sim_info, ignore_daycare=ignore_daycare)
bassinet.destroy(source=sim_info, cause='Assigned bassinet for baby.')
return True
definition_ids =
for bassinet in object_manager.get_objects_of_def_id_gen(*definition_ids):
while not bassinet.transient:
set_baby_sim_info_with_switch_id(bassinet, sim_info, ignore_daycare=ignore_daycare)
bassinet.destroy(source=sim_info, cause='Assigned bassinet for baby.')
return True
return False
I am not a python expert, and I hate trying to work out other people's uncommented python code because the lack of explicit typing makes it hard to work out what exact bit of data the function is expecting, especially when there are no usage examples in the existing python scripts.
I see two problems:
Sorry for the delay, I hadn't noticed that there was activity in this section. If you're spawning the bassinet with your script, it might also be more efficient to get the instance id from create_object and then assign rather than looping through the object list repeatedly and testing definition IDs.