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?

P#13405 2015-08-31 13:16 ( Edited 2015-08-31 23:42)

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.

P#13407 2015-08-31 13:39 ( Edited 2015-08-31 17:39)

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

P#13424 2015-08-31 17:39 ( Edited 2015-08-31 21:39)

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.

P#13429 2015-08-31 18:04 ( Edited 2015-08-31 22:04)

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.

P#13445 2015-08-31 19:42 ( Edited 2015-08-31 23:42)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 18:10:48 | 0.006s | Q:16