Saturday, May 21, 2016

Quest for random numbers...

Now that I am happy with the general ball physics of the game I want to implement the next aspect - enemies. For this game I have this idea to mash-up breakout and a shoot'em'up / space invaders type game together. Player's goal is to destroy the enemies with the ball. The enemies alone don't attack the player's paddle, but instead make the game more difficult by producing glitch effects... but this post is not about that.

This post is about me basically wasting a whole day, because I was afraid to code. I spent the whole day today and a lot of yesterday NOT doing code, because I had no idea where to start. Like I know what I want for the enemies to work. I want them to spawn at random(ish) time at random(ish) place on the "board" and move about. Then I want to add collision between enemies and the ball and a way to destroy them. That's all.

But because I am a noob at programming I didn't even know how to generate random number in Lua! This small thing stopped me from doing any real work on the game for more than 24h. This is stupid!


I spent wasted some time looking for tutorials for "spawning enemies at random +lua" and similar shit, but generally I just avoided coding or anything related to it because this task of adding randomly spawning enemies seemed too complex for my meager skills. Then it suddenly occurred to me that I am not supposed to code it all at once. I have already broken down the task into smaller chunks, so what I need to do is to tackle one chunk at a time. This was an eye opener and something that I will need to remember if I ever get scared of coding again.

LEARNING TO LOOK FOR ANSWERS.

So now I had a manageable task in front of me: learn how to call random numbers, especially between two numbers (handy for coordinates between 0 and 127). I can do this.

Sadly the Pico-8 manual is not very newbie friendly right now, so it wasn't much help. It did give me the RND function, so I had a starting point. Next I just played different games on Pico-8 to see which one of them had randomized enemies and lookup the source code. This didn't help as much, because a lot of those games didn't have any comments explaining what is happening. It did give me some ideas though. Lastly I did something that I should have done much earlier, googled "+lua +rnd" - and this really broke me out of my code scare. I found couple websites that explained exactly how RND works. However, PICO-8 uses a custom version of Lua so I had to test it inside my game to see what does and doesn't work. This last part helped immensely, because it broke my temporary fear of coding. After all I only was testing one small thing. Nothing scary.

So, if you are a newbie like me, and you are stuck because you don't know how to proceed, do this:
  1. Break down the issue into small chunks. As small as you can. Think of everything that your program needs to do to make this thing happen. Write them down if it helps. Then try to implement them one by one.
  2. Lookup manuals and other documentation for the engine/framework you are working with to find out how to do each step. For me it was Pico-8 manual, that is still in very early stages and not overly helpful. But it doesn't matter. It can put you on the right track.
  3. Google what you need to know. Not the whole task, just the thing you are currently working on from your list of small chunks. Learn about that thing.
    1. If you are a Pico-8 user, lookup how others solved that problem. Get into that source code and try to understand it.
  4. Test. Implement something small to check how it works. Either as a new or inside your current program. If you are worried that you will mess up your code - don't. Just save a backup.
  5. Test it in a different way. Maybe expand your test to get you closer to your big goal or test some other aspect of what you learned from the steps 2 and 3.
  6. Test more, until you feel that you know what you are doing with this thing.
Now you can implement (at least a bit of) your code to solve the issue and you have, and you have learned something new in the process. Best of all, you managed to code something when it felt impossible. You got this.

EDIT:

Just my luck. Someone had a random number related question in the Pico-8 BBS as I was writing this post. Those answers would have helped me a lot. I guess I should be more open to asking for people's help even with my noob questions. But in the long run, maybe I am learning more by finding the answers on my own. Hmmm? Anyway, here's a small skeleton I made while I was NOT coding.

No comments:

Post a Comment