Skip to main content
More explicit
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

Programming languages like Python have types, which determine what you can do with which piece of data. Using each variable in a way that's appropriate to its type is like putting a round peg in a round hole, or a square peg into a square hole.

When you try to do an operation that expects one type, but you give it a different, incompatible type, that's trying to shove a square peg into a round hole. The computer won't be able to make sense of the operation and it will throw an error.

That's what you have happening here. bones = pygame.sprite.Group() tells the computer "bones is a group that holds Sprite objects" (ie. it's a round hole to put round pegs into)

Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() tells the computer "Bone is a Surface object loaded from an image like so..." (ie. it's a square peg to put into a square hole)

bones.add(Bone) says "take that square peg (Surface) and shove it into that round hole (group of Sprite objects)"

So the compilercomputer errors-out and tells you that the Bone variable's type, pygame.Surface, does not have the shape that the bones variable's type, pygame.sprite.Group needs for its add method. It wants a Sprite that has an add_internal attribute, but you gave it a Surface which doesn't have that attribute.

AttributeError: 'pygame.Surface' object has no attribute 'add_internal'

So, first you need to make Sprite objects from the Surface objects you loaded from your images - think of it like an adapter to turn the square peg into a round peg - like so:

boneSprite = pygame.sprite.Sprite()
boneSprite.image = Bone
boneSprite.rect = Bone.get_rect()

Now that you have a Sprite that uses the Bone image, you can add it to your group like so:

bones.add(boneSprite)

This will not generate errors, because we're putting a round peg into a round hole now.

As described in the comments, this is all explained in existing answers, so please take the time to search for existing documentation and read it thoroughly to solve your problems faster in future.

Programming languages like Python have types, which determine what you can do with which piece of data. Using each variable in a way that's appropriate to its type is like putting a round peg in a round hole, or a square peg into a square hole.

When you try to do an operation that expects one type, but you give it a different, incompatible type, that's trying to shove a square peg into a round hole. The computer won't be able to make sense of the operation and it will throw an error.

That's what you have happening here. bones = pygame.sprite.Group() tells the computer "bones is a group that holds Sprite objects" (ie. it's a round hole to put round pegs into)

Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() tells the computer "Bone is a Surface object loaded from an image like so..." (ie. it's a square peg to put into a square hole)

bones.add(Bone) says "take that square peg (Surface) and shove it into that round hole (group of Sprite objects)"

So the compiler errors-out and tells you that the Bone variable's type, pygame.Surface, does not have the shape that the bones variable's type, pygame.sprite.Group needs for its add method. It wants a Sprite but you gave it a Surface.

So, first you need to make Sprite objects from the Surface objects you loaded from your images - think of it like an adapter to turn the square peg into a round peg - like so:

boneSprite = pygame.sprite.Sprite()
boneSprite.image = Bone
boneSprite.rect = Bone.get_rect()

Now that you have a Sprite that uses the Bone image, you can add it to your group like so:

bones.add(boneSprite)

This will not generate errors, because we're putting a round peg into a round hole now.

As described in the comments, this is all explained in existing answers, so please take the time to search for existing documentation and read it thoroughly to solve your problems faster in future.

Programming languages like Python have types, which determine what you can do with which piece of data. Using each variable in a way that's appropriate to its type is like putting a round peg in a round hole, or a square peg into a square hole.

When you try to do an operation that expects one type, but you give it a different, incompatible type, that's trying to shove a square peg into a round hole. The computer won't be able to make sense of the operation and it will throw an error.

That's what you have happening here. bones = pygame.sprite.Group() tells the computer "bones is a group that holds Sprite objects" (ie. it's a round hole to put round pegs into)

Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() tells the computer "Bone is a Surface object loaded from an image like so..." (ie. it's a square peg to put into a square hole)

bones.add(Bone) says "take that square peg (Surface) and shove it into that round hole (group of Sprite objects)"

So the computer errors-out and tells you that the Bone variable's type, pygame.Surface, does not have the shape that the bones variable's type, pygame.sprite.Group needs for its add method. It wants a Sprite that has an add_internal attribute, but you gave it a Surface which doesn't have that attribute.

AttributeError: 'pygame.Surface' object has no attribute 'add_internal'

So, first you need to make Sprite objects from the Surface objects you loaded from your images - think of it like an adapter to turn the square peg into a round peg - like so:

boneSprite = pygame.sprite.Sprite()
boneSprite.image = Bone
boneSprite.rect = Bone.get_rect()

Now that you have a Sprite that uses the Bone image, you can add it to your group like so:

bones.add(boneSprite)

This will not generate errors, because we're putting a round peg into a round hole now.

As described in the comments, this is all explained in existing answers, so please take the time to search for existing documentation and read it thoroughly to solve your problems faster in future.

typo, clarification
Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

Programming languages like Python have types, which determine what you can do with which piece of data. Using each variable in a way that's appropriate to its type is like putting a round peg in a round hole, or a square peg into a roundsquare hole.

When you try to do an operation that expects one type, but you give it a different, incompatible type, that's trying to shove a square peg into a round hole. The computer won't be able to make sense of the operation and it will throw an error.

That's what you have happening here. bones = pygame.sprite.Group() tells the computer "bones is a group that holds Sprite objects" (ie. it's a round hole to put round pegs into)

Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() tells the computer "Bone is a Surface object loaded from an image like so..." (ie. it's a square peg to put into a square hole)

bones.add(Bone) says "take that square peg (Surface) and shove it into that round hole (group of spriteSprite objects)"

So the compiler errors-out and tells you that the Bone variable's type, pygame.Surface, does not have the shape that the bones variable's type, pygame.sprite.Group needs for its add method. It wants a Sprite but you gave it a Surface.

So, first you need to make Sprite objects from the Surface objects you loaded from your images, - think of it like an adapter to turn the square peg into a round peg - like so:

boneSprite = pygame.sprite.Sprite()
boneSprite.image = Bone
boneSprite.rect = Bone.get_rect()

Now that you have a Sprite that uses the Bone image, you can add it to your group like so:

bones.add(boneSprite)

This will not generate errors, because we're putting a round peg into a round hole now.

As described in the comments, this is all explained in existing answers, so please take the time to search for existing documentation and read it thoroughly to solve your problems faster in future.

Programming languages like Python have types, which determine what you can do with which piece of data. Using each variable in a way that's appropriate to its type is like putting a round peg in a round hole, or a square peg into a round hole.

When you try to do an operation that expects one type, but you give it a different, incompatible type, that's trying to shove a square peg into a round hole. The computer won't be able to make sense of the operation and it will throw an error.

That's what you have happening here. bones = pygame.sprite.Group() tells the computer "bones is a group that holds Sprite objects" (ie. it's a round hole to put round pegs into)

Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() tells the computer "Bone is a Surface object loaded from an image like so..." (ie. it's a square peg to put into a square hole)

bones.add(Bone) says "take that square peg (Surface) and shove it into that round hole (group of sprite objects)"

So the compiler errors-out and tells you that the Bone variable's type, pygame.Surface, does not have the shape that the bones variable's type, pygame.sprite.Group needs for its add method. It wants a Sprite but you gave it a Surface.

So, first you need to make Sprite objects from the Surface objects you loaded from your images, like so:

boneSprite = pygame.sprite.Sprite()
boneSprite.image = Bone
boneSprite.rect = Bone.get_rect()

Now that you have a Sprite that uses the Bone image, you can add it to your group like so:

bones.add(boneSprite)

This will not generate errors, because we're putting a round peg into a round hole now.

As described in the comments, this is all explained in existing answers, so please take the time to search for existing documentation and read it thoroughly to solve your problems faster in future.

Programming languages like Python have types, which determine what you can do with which piece of data. Using each variable in a way that's appropriate to its type is like putting a round peg in a round hole, or a square peg into a square hole.

When you try to do an operation that expects one type, but you give it a different, incompatible type, that's trying to shove a square peg into a round hole. The computer won't be able to make sense of the operation and it will throw an error.

That's what you have happening here. bones = pygame.sprite.Group() tells the computer "bones is a group that holds Sprite objects" (ie. it's a round hole to put round pegs into)

Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() tells the computer "Bone is a Surface object loaded from an image like so..." (ie. it's a square peg to put into a square hole)

bones.add(Bone) says "take that square peg (Surface) and shove it into that round hole (group of Sprite objects)"

So the compiler errors-out and tells you that the Bone variable's type, pygame.Surface, does not have the shape that the bones variable's type, pygame.sprite.Group needs for its add method. It wants a Sprite but you gave it a Surface.

So, first you need to make Sprite objects from the Surface objects you loaded from your images - think of it like an adapter to turn the square peg into a round peg - like so:

boneSprite = pygame.sprite.Sprite()
boneSprite.image = Bone
boneSprite.rect = Bone.get_rect()

Now that you have a Sprite that uses the Bone image, you can add it to your group like so:

bones.add(boneSprite)

This will not generate errors, because we're putting a round peg into a round hole now.

As described in the comments, this is all explained in existing answers, so please take the time to search for existing documentation and read it thoroughly to solve your problems faster in future.

Source Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

Programming languages like Python have types, which determine what you can do with which piece of data. Using each variable in a way that's appropriate to its type is like putting a round peg in a round hole, or a square peg into a round hole.

When you try to do an operation that expects one type, but you give it a different, incompatible type, that's trying to shove a square peg into a round hole. The computer won't be able to make sense of the operation and it will throw an error.

That's what you have happening here. bones = pygame.sprite.Group() tells the computer "bones is a group that holds Sprite objects" (ie. it's a round hole to put round pegs into)

Bone = pygame.image.load(os.path.join("Images", "Bone.png")).convert_alpha() tells the computer "Bone is a Surface object loaded from an image like so..." (ie. it's a square peg to put into a square hole)

bones.add(Bone) says "take that square peg (Surface) and shove it into that round hole (group of sprite objects)"

So the compiler errors-out and tells you that the Bone variable's type, pygame.Surface, does not have the shape that the bones variable's type, pygame.sprite.Group needs for its add method. It wants a Sprite but you gave it a Surface.

So, first you need to make Sprite objects from the Surface objects you loaded from your images, like so:

boneSprite = pygame.sprite.Sprite()
boneSprite.image = Bone
boneSprite.rect = Bone.get_rect()

Now that you have a Sprite that uses the Bone image, you can add it to your group like so:

bones.add(boneSprite)

This will not generate errors, because we're putting a round peg into a round hole now.

As described in the comments, this is all explained in existing answers, so please take the time to search for existing documentation and read it thoroughly to solve your problems faster in future.