Update building.py

Result string in loop appended to list
This commit is contained in:
BlauFeuer 2017-02-10 16:51:47 -05:00 committed by Griatch
parent 61ffe5f9fa
commit 9a5b6969f3

View file

@ -364,14 +364,14 @@ class CmdCpAttr(ObjManipCommand):
self.caller.msg("|RCannot have duplicate source names when moving!") self.caller.msg("|RCannot have duplicate source names when moving!")
return return
string = "" result = []
for to_obj in to_objs: for to_obj in to_objs:
to_obj_name = to_obj['name'] to_obj_name = to_obj['name']
to_obj_attrs = to_obj['attrs'] to_obj_attrs = to_obj['attrs']
to_obj = caller.search(to_obj_name) to_obj = caller.search(to_obj_name)
if not to_obj: if not to_obj:
string += "\nCould not find object '%s'" % to_obj_name result.append("\nCould not find object '%s'" % to_obj_name)
continue continue
for inum, from_attr in enumerate(from_obj_attrs): for inum, from_attr in enumerate(from_obj_attrs):
try: try:
@ -387,18 +387,18 @@ class CmdCpAttr(ObjManipCommand):
if (clear and not (from_obj == to_obj and if (clear and not (from_obj == to_obj and
from_attr == to_attr)): from_attr == to_attr)):
from_obj.attributes.remove(from_attr) from_obj.attributes.remove(from_attr)
string += "\nMoved %s.%s -> %s.%s. (value: %s)" % (from_obj.name, result.append("\nMoved %s.%s -> %s.%s. (value: %s)" % (from_obj.name,
from_attr, from_attr,
to_obj_name, to_obj_name,
to_attr, to_attr,
repr(value)) repr(value)))
else: else:
string += "\nCopied %s.%s -> %s.%s. (value: %s)" % (from_obj.name, result.append("\nCopied %s.%s -> %s.%s. (value: %s)" % (from_obj.name,
from_attr, from_attr,
to_obj_name, to_obj_name,
to_attr, to_attr,
repr(value)) repr(value)))
caller.msg(string) caller.msg(result."".join(result)
class CmdMvAttr(ObjManipCommand): class CmdMvAttr(ObjManipCommand):
@ -660,7 +660,7 @@ class CmdDestroy(COMMAND_DEFAULT_CLASS):
string += " Objects inside %s were moved to their homes." % objname string += " Objects inside %s were moved to their homes." % objname
return string return string
string = "" result = []
for objname in self.lhslist: for objname in self.lhslist:
if '-' in objname: if '-' in objname:
# might be a range of dbrefs # might be a range of dbrefs
@ -668,13 +668,13 @@ class CmdDestroy(COMMAND_DEFAULT_CLASS):
for part in objname.split('-', 1)] for part in objname.split('-', 1)]
if dmin and dmax: if dmin and dmax:
for dbref in range(int(dmin), int(dmax + 1)): for dbref in range(int(dmin), int(dmax + 1)):
string += delobj("#" + str(dbref), True) result.append(delobj("#" + str(dbref), True))
else: else:
string += delobj(objname) result.append(delobj(objname))
else: else:
string += delobj(objname, True) result.append(delobj(objname, True))
if string: if string:
caller.msg(string.strip()) caller.msg("".join(result).strip())
class CmdDig(ObjManipCommand): class CmdDig(ObjManipCommand):
@ -1513,7 +1513,7 @@ class CmdSetAttribute(ObjManipCommand):
if not self.check_obj(obj): if not self.check_obj(obj):
return return
string = "" result = []
if "edit" in self.switches: if "edit" in self.switches:
# edit in the line editor # edit in the line editor
if len(attrs) > 1: if len(attrs) > 1:
@ -1530,25 +1530,25 @@ class CmdSetAttribute(ObjManipCommand):
for attr in attrs: for attr in attrs:
if not self.check_attr(obj, attr): if not self.check_attr(obj, attr):
continue continue
string += self.view_attr(obj, attr) result.append(self.view_attr(obj, attr))
# we view it without parsing markup. # we view it without parsing markup.
self.caller.msg(string.strip(), options={"raw":True}) self.caller.msg("".join(result).strip(), options={"raw":True})
return return
else: else:
# deleting the attribute(s) # deleting the attribute(s)
for attr in attrs: for attr in attrs:
if not self.check_attr(obj, attr): if not self.check_attr(obj, attr):
continue continue
string += self.rm_attr(obj, attr) result.append(self.rm_attr(obj, attr))
else: else:
# setting attribute(s). Make sure to convert to real Python type before saving. # setting attribute(s). Make sure to convert to real Python type before saving.
for attr in attrs: for attr in attrs:
if not self.check_attr(obj, attr): if not self.check_attr(obj, attr):
continue continue
value = _convert_from_string(self, value) value = _convert_from_string(self, value)
string += self.set_attr(obj, attr, value) result.append(self.set_attr(obj, attr, value))
# send feedback # send feedback
caller.msg(string.strip('\n')) caller.msg("".join(result).strip('\n'))
class CmdTypeclass(COMMAND_DEFAULT_CLASS): class CmdTypeclass(COMMAND_DEFAULT_CLASS):
@ -2365,38 +2365,37 @@ class CmdScript(COMMAND_DEFAULT_CLASS):
if not obj: if not obj:
return return
string = "" result = []
if not self.rhs: if not self.rhs:
# no rhs means we want to operate on all scripts # no rhs means we want to operate on all scripts
scripts = obj.scripts.all() scripts = obj.scripts.all()
if not scripts: if not scripts:
string += "No scripts defined on %s." % obj.get_display_name(caller) result.append("No scripts defined on %s." % obj.get_display_name(caller))
elif not self.switches: elif not self.switches:
# view all scripts # view all scripts
from evennia.commands.default.system import format_script_list from evennia.commands.default.system import format_script_list
string += format_script_list(scripts) result.append(format_script_list(scripts))
elif "start" in self.switches: elif "start" in self.switches:
num = sum([obj.scripts.start(script.key) for script in scripts]) num = sum([obj.scripts.start(script.key) for script in scripts])
string += "%s scripts started on %s." % (num, obj.get_display_name(caller)) result.append("%s scripts started on %s." % (num, obj.get_display_name(caller)))
elif "stop" in self.switches: elif "stop" in self.switches:
for script in scripts: for script in scripts:
string += "Stopping script %s on %s." % (script.get_display_name(caller), result.append("Stopping script %s on %s." % (script.get_display_name(caller),
obj.get_display_name(caller)) obj.get_display_name(caller)))
script.stop() script.stop()
string = string.strip()
obj.scripts.validate() obj.scripts.validate()
else: # rhs exists else: # rhs exists
if not self.switches: if not self.switches:
# adding a new script, and starting it # adding a new script, and starting it
ok = obj.scripts.add(self.rhs, autostart=True) ok = obj.scripts.add(self.rhs, autostart=True)
if not ok: if not ok:
string += "\nScript %s could not be added and/or started on %s." % ( result.append("\nScript %s could not be added and/or started on %s." % (
self.rhs, obj.get_display_name(caller) self.rhs, obj.get_display_name(caller)
) ))
else: else:
string = "Script |w%s|n successfully added and started on %s." % ( result.append("Script |w%s|n successfully added and started on %s." % (
self.rhs, obj.get_display_name(caller) self.rhs, obj.get_display_name(caller)
) ))
else: else:
paths = [self.rhs] + ["%s.%s" % (prefix, self.rhs) paths = [self.rhs] + ["%s.%s" % (prefix, self.rhs)
@ -2406,20 +2405,20 @@ class CmdScript(COMMAND_DEFAULT_CLASS):
for path in paths: for path in paths:
ok = obj.scripts.stop(path) ok = obj.scripts.stop(path)
if not ok: if not ok:
string += "\nScript %s could not be stopped. Does it exist?" % path result.append("\nScript %s could not be stopped. Does it exist?" % path)
else: else:
string = "Script stopped and removed from object." result = ["Script stopped and removed from object."]
break break
if "start" in self.switches: if "start" in self.switches:
# we are starting an already existing script # we are starting an already existing script
for path in paths: for path in paths:
ok = obj.scripts.start(path) ok = obj.scripts.start(path)
if not ok: if not ok:
string += "\nScript %s could not be (re)started." % path result.append("\nScript %s could not be (re)started." % path)
else: else:
string = "Script started successfully." result = ["Script started successfully."]
break break
caller.msg(string.strip()) caller.msg("".join(result).strip())
class CmdTag(COMMAND_DEFAULT_CLASS): class CmdTag(COMMAND_DEFAULT_CLASS):