Skip to content
Sign upLog in

Deleting a Block

Profile icon
51LV3RC0D3R

So I am creating a game in pygame
I was wondering how to delete the block in class Level_01.

DudeHexafandra

You are viewing a single comment. View All
Profile icon
[deleted]

Example

level.pop(1) #This remove's place 2 in the array (we count from 0 in Python)

Profile icon
51LV3RC0D3R

@ZhongRietveld
I don't get what you are saying. I tried screen.pop(1) because I couldn't use level as I was in line 291 in the function main(). So when I tried running it, it said that 'pygame.Surface' has no attribute pop.

Profile icon
[deleted]

@DudeHexafandra
No, you use the varible name from the array so,

level.pop(1)

Profile icon
[deleted]

@ZhongRietveld
Is this what you neat to let is work as you want to?

Profile icon
51LV3RC0D3R

@ZhongRietveld
I tried it and I think I get what you are doing, but the problem is that I am writing my

level.pop(1)

in

def main():

and it says that level is undefined.

Profile icon
[deleted]

@DudeHexafandra
that is, because its a local var so you have to return it

#return level
#Use the function with the return
new_level=<class_name>.<function_name()
#function name is option, because the init()
#Is always executed

Profile icon
[deleted]

@ZhongRietveld
If I am right.

Profile icon
51LV3RC0D3R

@ZhongRietveld
So just to make sure I got what you said the

<class_name>

is Level.02 and the

function_name()

is what exactly in this case?
Sorry, i am just a little new to pygame.

Profile icon
[deleted]

@DudeHexafandra
A bit what i mean is that you use <funtcion_name> from a class only when the builtin function is not init().