ILOVEPIE Posted August 28, 2011 Posted August 28, 2011 this is the code i am having problems with ... it won't work it just keeps giving errors about how you cant use bitwize operations on type slice with a mask of type int import random import time import os #import struct import array class bf(object): def __init__(self,value=0): self._d = value def __getitem__(self, index): return (self._d >> index) & 1 def __setitem__(self,index,value): value = (value&1L)<<index mask = (1L)<<index self._d = (self._d & ~mask) | value def __getslice__(self, start, end): mask = 2L**(end - start) -1 return (self._d >> start) & mask def __setslice__(self, start, end, value): mask = 2L**(end - start) -1 value = (value & mask) << start mask = mask << start self._d = (self._d & ~mask) | value return (self._d >> start) & mask def __int__(self): return self._d def _shinygen(pokemonid): """Returns Tuple of Shiny TID and SID for given PID""" shiny=False n=0 while shiny == False: tid=bf(random.getrandbits(16)) sid=bf(random.getrandbits(16)) pid=bf(pokemonid) n +=1 shiny = True for i in range(0,13): if int(pid[15-i]) + int(pid[31-i])+ int(tid[15-i])+ int(sid[15-i])== 3: shiny = False break elif int(pid[15-i])+ int(pid[31-i])+ int(tid[15-i])+ int(sid[15-i])== 1: shiny = False break if shiny: return (tid,sid) else: return False print "Please type in the file address of the pokemon" path = raw_input("-") path = os.path.normpath(path) file = open(path, "rb") pkm = array.array("i",file.read()) file.close() TID,SID =_shinygen(pkm[0x00:0x04]) pkm[0x0C:0x0E]=int(TID) pkm[0x0E:0x10]=int(SID) file = open(path,"wb") pkm.tofile(file) file.close() print "Your Pokemon is now Shiny!" time.sleep(20)
arcee Posted August 29, 2011 Posted August 29, 2011 Like I replied in your PM.. I would suggest you put these two sections into separate modules. It gets rather messy. (shinygen and the main py) I did so, put shinygen into a 'src' folder and added __init__.py From just looking at it, I can tell you need to.. Fix your indents and make them consistent. The last 14-15 lines or so need indents. Your class has spaces for indents, but your 'shinygen' function has tabs. Again, make it consistent. Python is a stickler for indents and how they're used. Oh, btw, I don't know what """Returns Tuple of Shiny TID and SID for given PID""" is doing there. Make it into a print, or a # note. With only one " on each side. Add a while true: statement to run the main module. You don't need time.sleep, it shouldn't automatically exit (make it automatically loop instead, it's better). Don't use arrays in int() arguments, use a string or something. Have you gotten it to work? I'm still not understanding why you need this "shiny generator" in your GTS program, though.
ILOVEPIE Posted August 31, 2011 Author Posted August 31, 2011 """ is a special string designation used by pydoc for describing a function It's not an array it's a bitfield
arcee Posted August 31, 2011 Posted August 31, 2011 then tell me why traceback gave me that error. 'pkm' is an array. also, you never mentioned you were using pydoc.
ILOVEPIE Posted September 5, 2011 Author Posted September 5, 2011 I am having troubles converting a binary slice to an integer and then overwriting a binary slice in an array...
ILOVEPIE Posted September 10, 2011 Author Posted September 10, 2011 ok... it is now writing to file... exept the filesize is now chainging :mad: import random import time import os import struct import binascii import array class bf(object): def __init__(self,value=0): self._d = value def __getitem__(self, index): return (self._d >> index) & 1 def __setitem__(self,index,value): value = (value&1L)<<index mask = (1L)<<index self._d = (self._d & ~mask) | value def __getslice__(self, start, end): mask = 2L**(end - start) -1 return (self._d >> start) & mask def __setslice__(self, start, end, value): mask = 2L**(end - start) -1 value = (value & mask) << start mask = mask << start self._d = (self._d & ~mask) | value return (self._d >> start) & mask def __int__(self): return self._d def _shinygen(pokemonid): """Returns Tuple of Shiny TID and SID for given PID""" shiny=False n=0 while shiny == False: tid=bf(random.getrandbits(16)) sid=bf(random.getrandbits(16)) pid=bf(pokemonid) n +=1 shiny = True for i in range(0,13): if int(pid[15-i]) + int(pid[31-i])+ int(tid[15-i])+ int(sid[15-i])== 3: shiny = False break elif int(pid[15-i])+ int(pid[31-i])+ int(tid[15-i])+ int(sid[15-i])== 1: shiny = False break if shiny: return (tid,sid) else: return False print "Please type in the file address of the pokemon" path = raw_input("-") path = os.path.normpath(path) file = open(path, "rb") pkm = array.array("i",file.read()) file.close() #TID,SID =_shinygen(int(pkm[0x00:0x04].tostring())) TID,SID =_shinygen(int(binascii.hexlify(pkm[0x00:0x04]),16)) print bin(int(TID)) pkm[0x0C:0x0E]=array.array("i",struct.pack("i",int(TID))) pkm[0x0E:0x10]=array.array("i",struct.pack("i",int(SID))) file = open(path,"wb") pkm.tofile(file) file.close() print "Your Pokemon is now Shiny!" time.sleep(20)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now