It looks like you're new here. If you want to get involved, click one of these buttons!
Yesterday I had the amazing idea to create a game where you play as a ghost and you have to take over people's bodies to solve puzzles. One of my problems is that I have no programming experience exept from what I learned from the forums and from little projects I made myself. I know it's hard to make good games and that it takes a lot of time but I still want to give it a shot. Another problem is that for some reason when I put down multiple npc's I can't take over bodies or leave bodies. If you're willing to share a solution, please don't make it too complicated as I don't want any code in my project that I don't understand!
Comments
Here's the code:
I know it's kind of messy but I just found out how classes work so don't expect me to write everything super short but if it would help someone, you can use it for your own projects.
By the way, the game works properly when there's only one npc
It looks like you need to change takenover to self.takenover in th npc class init function. Right now their global variables so the program can't tell which npc is taken over.
Thanks, I don't know how I missed that though :-O but now I'm having another problem ~X(
Well, I'll try to fix it myself before I ask for help again.
I don't like to ask it but could anyone help me with my other problem? Somehow the buttons act weird after 1 npc and I can't figure out why it does that... I edited the code above with the updated version.
Don't be afraid to help :P
(I really want to continue the game as soon as I can.)
@G_nex I know you're in a hurry, so instead of trying to figure out why your code isn't working, it was faster to write another version of what I think you're doing to give you some other ideas. I didn't go into the detail you did. When the ghost and other sprites overlap, I put some text (switch) at the top of the screen. Tap it once to switch which sprite will then move. Only the ghost can switch with another sprite.
@G_nex Make the change I show below in the function NPC:draw(). Also, you're mixing values. Some places you set an initial value to false, then you set it later on to some number. Also, you use the variable "ask", but it's never set to anything, so it's nil. You need to go thru your code and find those kind of things, or you're going to have more trouble finding errors as the code gets bigger.
@G_nex - what @dave1707 points out suggests that you may be rushing your code and writing too much at a time. This makes it very difficult to find errors.
Try making very small changes and testing them properly before carrying on. This is actually a lot quicker overall.
@Ignatz Making small changes also helps for debugging, sometimes I've written a lot of code and pressed the play button to find there's an error in the ton of code I just wrote, and it tends to not tell me what line, or the line number can be incorrect.
@TheSkyCoder - yes, that's exactly the point I was trying to make.
@dave1707 Thanks for helping' I said from the beginning my code was messy, but for now I'll take a break in writing new code and try to fix the current one.
@Ignatz @SkyTheCoder Thanks for the tip. These kind of small tips really make a big difference at the end.