Log In  


Currently, in Heavy Duty Sprinkler I'm burning through tokens like a crazed maniac with AK-47 and a flamethrower and I worry that by the end of it I will have no tokens left. What are some of the ways you can reduce token amount?



You can always start by being more restrictive with function names and comments. You can also try something like a Haxe Compiler so you can write code normally and then reduce it's size. This effectively allows you to still write readable code but then optimize it for space.

link: A good thread to read up on the limitations and some of Zep's own thoughts on the matter.


I don't like haxe, much prefer Lua. Thanks for the thread tho.


The best advice is really just to avoid duplicate code and to design around the limitations. Games need to be quite simple at their core.

Function names and comments do not count towards the token count, so as long as it's under 32k chars you can go nuts.


I don't know, generally just look for places that are costing you a lot of tokens: table initialization, complicated function calls, repeated arithmetic, pointless abstraction.

Helper functions help. For example:

-- 30 tokens
spr(p.sn,p.x,p.y,p.sw,p.sh,p.fh,p.fv)

-- 30+6 tokens
function draw_sprite(s)
 spr(s.sn,s.x,s.y,s.sw,s.sh,s.fh,s.fv)
end

-- 4 tokens
draw_sprite(p)

Even if you only call draw_sprite() twice in your code, you're up 16 tokens over two SPR() calls.

You can do stuff like: use temp variables instead of repeating calculations, or use MID(), MIN() and MAX() to do clamping that you'd otherwise do with IF/THENs, or write a function that lets you write A=UNPACK("1,3,5,9,12,3") instead of A={1,3,5,9,12,3}.

Though none of that stuff is as important as just limiting the design choices.



[Please log in to post a comment]