Day 7- Loopy

Day 7- Loopy

Quote of the Day: “Player has successfully moved to level table!” – Unity console

Music of the Day: A mix of old and new- Rush and Ghost B.C. I have rediscovered my love for Rush.

Today I have had the immensely frustrating experience of knowing EXACTLY what the problem is, and trying everything to fix it with no success, and the immensely satisfying experience of actually fixing it. Here’s a short warning: Today was extremely technical. I’ll try to keep all the techno-jargon as simple as I can.

So, as is often the case not only with game design but computer science in general, you make a piece of code, get it working, pat yourself on the back and call it a day. Then someone else comes and tests it and points out a ton of problems. This was the story of today with the teleporter. I came in expecting to move on to powerups, but instead spent the entire day again fixing the teleporter. The (initial) issue was that the teleporter would take almost a minute to move the player to the next level, and would even on occasion crash Unity. Now, I had naively thought this to be because of my computer, which is pretty low-spec and has almost no storage space remaining. Turns out, it was because there was an infinite loop. For those of you who don’t know what that means- it’s pretty close to what it sounds like. Some piece of data is being changed over and over again without stopping by calling itself infinitely. To give you an example:

while(0 < 1)

{

do something

}

Obviously, 0 is ALWAYS less than 1, so the “do something” bit of code is executing nonstop. Looping to infinity. The way my program was doing it was a lot more complicated, but I’ll explain it as best I can.

So, at its most basic, I was spawning an infinite amount of teleporters one on top of another in the same spot. This meant than when a player tripped on, they tripped all of them, so the computer was selecting the next level at random as many times as there were teleporters, all the while more and more teleporters were being created and triggered. Problem. This is where I became frustrated, because in my code (I’m actually not that bad of a programmer, thank you), I had a check for this.  A boolean (true/false) that would be used to check if there was an already existing teleporter, and if so not spawn any more. So for more than an hour I sat there, changing code here and there trying to figure out why in the hell my conditional wasn’t working. The reason (And warning this is gonna get confusing): The entire teleport logic was all on one script. This meant that one piece of code would select a new level to go to, put down the teleporter, move the player when triggered, and reset in the next level. The problem with that is that the script had to be attached to an already existing Game Object (some piece in the game) to be able to spawn in the first teleporter. So, this Game Object would spawn in a teleporter, which would then have that earlier mentioned boolean value set to false rather than true, so it would spawn another, which would spawn another, and so on and so on. The solution: split the script in two.

Which is exactly what I did. There are now two separate pieces of code, one that handles the selection of the next level and creation of the singular teleporter, and one that actually moves the player. The solution was actually super simple, as is also often the case. The trick is getting to it. Next up on the to-do list: make data carry over between levels. Right now, the score is the only consistent thing between levels (e.g. if you had a score of 500,000 on the first level you would still have that same score after going through the teleporter to the next level). However, the health of the player and any active powerup effects were not carried over. I messed around with it a bit, getting some things to work and breaking others, but I didn’t have much time left before I needed to leave. That will be tomorrows project, so stay tuned.

If you’ve made it this far, congratulations! You get a link to the Steam launch trailer (it’s a bit outdated, but gives you an idea of what the game is like if you haven’t seen it before). https://www.youtube.com/watch?v=1P0nL1SYDOQ

 

Advertisements

One thought on “Day 7- Loopy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s