I’m just started trying out this new programming platform recently and am trying to see what I can do.
I’m still not really used to how things work in this language (so bear with me) and have seem to run into a bug in one of my test programs. The game I’m trying to make essentially is supposed to be a 2d scrolling enemy survival game where random enemies spawn in random locations and you are trying to avoid/destroy the enemies by collecting coins from dead enemies and using those coins to give abilities to your character.
I seem to be having troubles with the part where it spawns random enemy “clones”. Basically the program that I have makes an enemy and picks a sprite from the “enemy types” list. Currently the list only has 4 test character in it. When an enemy enters it adds itself to one of the 4 “enemy” arrays according to its types. Off to the side I also have a forever block that updates each of the scrolling clones position based off their scrollx and scrolly.
The problem that I am having is that the program seems to only make one enemy “clone” per each type (four). I can’t seem to see what the problem is or why it is doing this. Am I missing something?
Ok so from my own experience it is known to me this isn’t a bug but just how the game runs, I’m not a master so idk how to fix it but I usually copy paste all the functions for an enemy and change its sprite aka the red part
Usually us Makecoders are pretty eager to answer questions, but it seems yours got missed! Anyways, the problem here is that the list of sprite types is really a list of sprites! Additionally, when you use the Bad Guy variable in the game update 500 loop, you aren’t making a new sprite, you are just making Bad Guy point to one of the sprites in the list!
So what happens is that you create 4 sprites when you make the list, and then you repeatedly move them around randomly.
To fix this, I would make your list into a list of just the images and have the sprite creation somewhere else, though, personally, I would just get rid of your list entirely. Instead, I would make a variable that is set to a random value between 0 and 3 at the start of the loop and have a large block of “if else”s that create each sprite depending on the random value.
A few other things:
There’s a “background color” block in the Scene tab that you might be interested in… and if you are trying to make a contained map with borders, you should use tilemaps (also the Scene tab)
If you aren’t going to make each enemy type have different behavior, then you really don’t need them to have different types. If you make them all under one type, all the sprite collision detection you create later will be much simpler!
Thanks a lot for answering. I was getting worried that the question was going to get skipped, I appreciate it.
I think I can follow what you said, if anything else comes up I might ask some more questions, I do want the the different “types” to have different behaviors. Ill see what I can do.
you are making a new sprite, so if you want make a lot of sprites you can just use that. When you put that into a variable, you aren’t… uhhh… how to explain this… that variable is not really that sprite…? It’s really a pointer to it, and the sprite is really contained in the “list of all sprites of type (…)”, so you can use one variable and every time something like this code runs…
You are creating a sprite, adding it the the “list of all sprites of kind…” list, and then setting that variable to be a pointer to that sprite, which means that when you call that code again, the sprite you create doesn’t overwrite the previous sprite. If you want to effect the sprite you just created, then use the variable that you just assigned to that sprite, and if you want to effect all of the sprites of that kind, you have to loop through all of them with a For loop.
If you really need to effect each sprite in a “kind” differently, long after you’ve created them, then you might want to look at the Sprite Data extension!
Ok. So when you use the block “sprite (picture) of kind (type)” you are making a sprite, and when you put it in a variable, the sprite you just created denotes to that variable, and every time you create a sprite, it does not overwrite the previous sprite. That makes a lot more sense now, thank you!
ps. I am using the sprite data extension, it is very useful (for anyone else following this post)