简体   繁体   中英

MCEdit filter - String Index out of Range Python

Used for an MCEdit Filter:

Get Error: String Index out of range

inputs = (
    ("Change Relative Values", True),
    ("Change Exact Values", True),
    ("Use Selected Region", False),
    ("Min X:", 0),
    ("Max X:", 0),
    ("Min Y:", 0),
    ("Max Y:", 0),
    ("Min Z:", 0),
    ("Max Z:", 0),
    ("dx", 0),
    ("dy", 0),
    ("dz", 0)
)

formatCode = unichr(167)

def perform(level, box, options):
    dx = options["dx"]
    dy = options["dy"]
    dz = options["dz"]
    minx = options["Min X:"]
    miny = options["Min Y:"]
    minz = options["Min Z:"]
    maxx = options["Max X:"]
    maxy = options["Max Y:"]
    maxz = options["Max Z:"]
    relative = options["Change Relative Values"]
    exact = options["Change Exact Values"]
    selected = options["Use Selected Region"]

    for (chunk, slices, point) in level.getChunkSlices(box):
        for t in chunk.TileEntities:
            x = t["x"].value
            y = t["y"].value
            z = t["z"].value

            if x >= box.minx and x < box.maxx and y >= box.miny and y < box.maxy and z >= box.minz and z < box.maxz and t["id"].value == "Control":
                command = t["Command"].value
                if command[0] == "/":
                    command = command[1:]

                words = command.split(" ")
                for word in range(len(words)):
                    if words[word][0] == "@" and len(words[word]) >= 4 and words[0] != "give" and exact:
                        subparams = words[word][3:len(words[word])-1].split(",")
                        if len(subparams) >= 1 and subparams[0].find("=") == -1:
                            if (int(subparams[0]) <= maxx and int(subparams[0]) >= minx and not selected) or (int(subparams[0]) >= box.minx and int(subparams[0]) <= box.maxx-1 and selected):
                                subparams[0] = str(int(subparams[0])+dx)
                        if len(subparams) >= 2 and subparams[1].find("=") == -1:
                            if (int(subparams[1]) <= maxy and int(subparams[1]) >= miny and not selected) or (int(subparams[1]) >= box.miny and int(subparams[1]) <= box.maxy-1 and selected):
                                subparams[1] = str(int(subparams[1])+dy)
                        if len(subparams) >= 3 and subparams[2].find("=") == -1:
                            if (int(subparams[2]) <= maxz and int(subparams[2]) >= minz and not selected) or (int(subparams[2]) >= box.minz and int(subparams[2]) <= box.maxz-1 and selected):
                                subparams[2] = str(int(subparams[2])+dz)
                        for inx in range(len(subparams)):
                            frags = subparams[inx].split("=")
                            if frags[0] == "x":
                                if (int(frags[1]) <= maxx and int(frags[1]) >= minx and not selected) or (int(frags[1]) >= box.minx and int(frags[1]) <= box.maxx-1 and selected):
                                    frags[1] = str(int(frags[1]) + dx)
                            if frags[0] == "y":
                                if (int(frags[1]) <= maxy and int(frags[1]) >= miny and not selected) or (int(frags[1]) >= box.minz and int(frags[1]) <= box.maxy-1 and selected):
                                    frags[1] = str(int(frags[1]) + dy)
                            if frags[0] == "z":
                                if (int(frags[1]) <= maxz and int(frags[1]) >= minz and not selected) or (int(frags[1]) >= box.minz and int(frags[1]) <= box.maxz-1 and selected):
                                    frags[1] = str(int(frags[1]) + dz)
                            subparams[inx] = "=".join(frags)
                        words[word] = words[word][0:3] + ",".join(subparams) + "]"

                if (words[0] == "tp" or words[0] == "spawnpoint" or words[0] == "summon") and len(words) >= 5:
                    if exact == True:
                        if words[2][0] != "~":
                            if (int(words[2]) <= maxx and int(words[2]) >= minx and not selected) or (int(words[2]) >= box.minx and int(words[2]) <= box.maxx-1 and selected):
                                words[2] = str(int(words[2]) + dx)
                        if words[3][0] != "~":
                            if (int(words[3]) <= maxy and int(words[3]) >= miny and not selected) or (int(words[3]) >= box.miny and int(words[3]) <= box.maxy-1 and selected):
                                words[3] = str(int(words[3]) + dy)
                        if words[4][0] != "~":
                            if (int(words[4]) <= maxz and int(words[4]) >= minz and not selected) or (int(words[4]) >= box.minz and int(words[4]) <= box.maxz-1 and selected):
                                words[4] = str(int(words[4]) + dz)
                    if relative == True:
                        if words[2][0] == "~":
                            if (int(words[2][1:]) <= maxx and int(words[2][1:]) >= minx and not selected) or (int(words[2][1:]) >= box.minx and int(words[2][1:]) <= box.maxx-1 and selected):
                                words[2][1:] = "~"+str(int(words[2][1:]) + dx)
                        if words[3][0] == "~":
                            if (int(words[3][1:]) <= maxy and int(words[3][1:]) >= miny and not selected) or (int(words[3][1:]) >= box.miny and int(words[3][1:]) <= box.maxy-1 and selected):
                                words[3][1:] = "~"+str(int(words[3][1:]) + dy)
                        if words[4][0] == "~":
                            if (int(words[4][1:]) <= maxz and int(words[4][1:]) >= minz and not selected) or (int(words[4][1:]) >= box.minz and int(words[4][1:]) <= box.maxz-1 and selected):
                                words[4] = "~"+str(int(words[4][1:]) + dz)


                if (words[0] == "setblock" or words[0] == "testforblock") and len(words) >= 5:
                    if exact == True:
                        if words[1][0] != "~":
                            if (int(words[1]) <= maxx and int(words[1]) >= minx and not selected) or (int(words[1]) >= box.minx and int(words[1]) <= box.maxx-1 and selected):
                                words[1] = str(int(words[1]) + dx)
                        if words[2][0] != "~":
                            if (int(words[2]) <= maxy and int(words[2]) >= miny and not selected) or (int(words[2]) >= box.miny and int(words[2]) <= box.maxy-1 and selected):
                                words[2] = str(int(words[2]) + dy)
                        if words[3][0] != "~":
                            if (int(words[3]) <= maxz and int(words[3]) >= minz and not selected) or (int(words[3]) >= box.minz and int(words[3]) <= box.maxz-1 and selected):
                                words[3] = str(int(words[3]) + dz)
                    if relative == True:
                        if words[1][0] == "~":
                            if (int(words[1][1:]) <= maxx and int(words[1][1:]) >= minx and not selected) or (int(words[1][1:]) >= box.minx and int(words[1][1:]) <= box.maxx-1 and selected):
                                words[1] = "~"+str(int(words[1][1:]) + dx)
                        if words[2][0] == "~":
                            if (int(words[2][1:]) <= maxy and int(words[2][1:]) >= miny and not selected) or (int(words[2][1:]) >= box.miny and int(words[2][1:]) <= box.maxy-1 and selected):
                                words[2] = "~"+str(int(words[2][1:]) + dy)
                        if words[3][0] == "~":
                            if (int(words[3][1:]) <= maxz and int(words[3][1:]) >= minz and not selected) or (int(words[3][1:]) >= box.minz and int(words[3][1:]) <= box.maxz-1 and selected):
                                words[3] = "~"+str(int(words[3][1:]) + dz)


                t["Command"] = TAG_String(" ".join(words))

                chunk.dirty = True

Which line is causing the string index error? A string index out of range error is raised when you try to use a specific index in a string that does exist. For example,the following string "text" is equivalent to t . the minimum index in this string is t[0] and the maximum is is t[3] If I try to do something with t[4] then it will raise the error you gave.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM