Here is my code, with a small debug loop...
So I create foo1 and foo2, then go throught the abilites of foo1, the second ability of foo1 is to change_to foo2 so it does, taking its arguments and its abilites(here is the question), as the ability of foo2 has self so it effects itself as an instance, running self.rotate as the new ability of foo1, will now change the target rotation of foo2 instance instead of foo1, so how can I while keeping this general structure make so when the abilites are copied, they now as self effect the instance instead of the other...
I didnt try much, asking AI, changing to import copy...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
class foo: def __init__( self , message = "hello Damien" , rotation = 0 ): self .message = message self .rotation = rotation self .target_rotation = rotation def rotate( self ): if self .rotation = = 0 : self .target_rotation = 30 else : self .target_rotation = 0 def great( self ): print ( self .message) def change_to( self , other): self .message = other.message self .rotation = other.rotation self .target_rotation = other.target_rotation self .ability1 = other.ability1 self .ability2 = other.ability2 def update( self ): if self .rotation ! = self .target_rotation: if self .target_rotation = = 30 : self .rotation + = 1 else : self .rotation - = 1 def ability1( self ): pass def ability2( self ): pass class foo1(foo): def ability1( self ): self .rotate() def ability2( self ): self .change_to(foo2) class foo2(foo): def ability1( self ): self .rotate() def ability2( self ): self .great() foo1 = foo1() foo2 = foo2(message = "hello world" ) while True : print ( "-----------" ) print ( "msg: " + str (foo1.message)) print ( "rot: " + str (foo1.rotation)) print ( "target_rot: " + str (foo1.target_rotation)) inp = str ( input ( "> " )) if inp = = "a" : if foo1.rotation = = 0 : foo1.ability1() elif foo1.rotation = = 30 : foo1.ability2() # exit ask for input print (foo1.target_rotation) foo1.update() |
I didnt try much, asking AI, changing to import copy...