Hacktoberfest 2021, PR #1
Tags: gamedev, gamejam, pixelart, hacktoberfest2021
Published: 2021-10-02 15:15:41

> This article was taken from my Ko-Fi page, where you check more of my stuff, and support me if you wish to!
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/L4L81GBPX)


Now, onto the article!

[Clock Mage](https://achie.itch.io/clock-mage) was a game jam entry of mine for the first [My little Roguelike](https://itch.io/jam/mylittleroguelike1/rate/665337) jam back in 2020. I really liked the jam the people were amazing, the submissions awesome, and overall i really got into the mood of programming, even had a few livestreams, and a lot of progress [tweets](https://twitter.com/Achie7240/status/1269743100014059522), so i was pretty happy with it.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bqkp55vvfor2eggt83ch.png)

So happy, that it i wanted to [remake the whole thing in the Godot Game Engine](https://github.com/Achie72/void-break), to expand on it, as i hit a major roadblock in the PICO-8 project, namely tokens. The "engine" has several hard limits on your code (to invoke oldschool programming challanges and feels) and one of them is the infamous 8192 tokens. I struck it several times during the development, cut it back a few times, but decided that a small scope may just be better for the project, and left it after a few little updates, and turned to the Godot remake.

That is going pretty well, but i alway had a longing to finish and polish up the PICO-8 version, which i started working on, but soon hit the roadmark of the tokens again. Well, nothing left, to dust down my "skill" and learn a bit more about what and how to optimise, so in the end this [Pull Request](https://github.com/Achie72/clock_mage/pull/2) was born, freeing up almost a hundred tokens with one easy trick.

Local variables. In PICO-8, typing `player.health` counts as two tokens, so if you really depend on these kind of data during a function it's much better to just declare a `local health = player.health`, which cost 4 (health, =, player, health), so if i can replace 8 of these calls, it'll only use 12 tokens instead of 16, which might seem low, but it will accumulate quickly. This really helps if your UI's position depends on the players position.

There are a few quick fixes included in the PR, which i did not comment on sadly. 

One of them is the `director.maxCredit = flr(director.maxCredit/2)` line, which honestly is a really big deal. My game depends on the so called `Director`, which spawns chest, enemies, sets costs, rewards etc... On each stage there is a teleport which you need to activate to progress, if you can survive a minute. During this time the Directors spawn credit is doubled to enable way more enemies to spawn, and i somehow forgot to reset it...

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4nodgga7fxsj8ph0d72.png)


The other is pretty closely related, and just as "dumb". I'm calculating a very simple difficulty in the game (time spent and level count), and for a long time i did not notice that i do not apply any of this. "How can you not notice that?" you may ask, and my answer is the issue just describe above. As i did not reset the teleporter event credit spike, the game got harder on it's own, and with a much higher spike than i originally wanted. One issue masked the other, so now things should be okay on this front.

Future plans are to reduce tokens even more, my enemy AI part is full of these kind of these, and maybe optimise, and some day we may have some space to add a boss to the game as well.

If you also want to join the Hacktoberfest 2021 just click the link, and the page will introduce you to everything you need to know!

[https://hacktoberfest.digitalocean.com/](https://hacktoberfest.digitalocean.com/)

Thanks for reading and have a nice day!



Other social sites:
🐦 [Twitter](https://twitter.com/Achie7240)
📷 [Instagram](https://www.instagram.com/justanerdlife/)
🎥 [Twitch](https://www.twitch.tv/achie7240)
🎬 [YouTube](https://www.youtube.com/channel/UCzWXrvo-Pj7_KDv4w4q-4Kg)



Games and devlogs i made: 
⌨️ [GitHub repos](https://github.com/Achie72)
🎮 [Itch.io](https://achie.itch.io/)
🕹️ [Newgrounds](https://achie72.newgrounds.com/)


All my links in one place:
[Linktr.ee](https://linktr.ee/AchieGameDev)