This weeks major distraction from blogging here has been time. I haven’t lacked it but I have been playing with it.
I really didn’t want to work on time just yet, I wanted to add input control to cepl so that I could let people actually play with what I have been doing. Oddly though my brain wouldn’t let me, it was one of those times in creativity that you get overruled by the voice in your head and no matter how hard you try to start working on something your brain drags you back to what it wants to be working on.
So I gave in and dropped working on input and had a look at time instead.
Time is intrinsically woven into games, and how you handle it has major impacts on how your game code is structured. As I’m working in a very non-standard language I feel very free to go looking for non-standard ways of doing things.
It’s been a beautiful feeling as I have really felt like I’m exploring ideas rather than just implementing them. I go on gut instinct and the mere action of writing the idea out in code reals the pitfalls as well as the advantages to the idea.
While I was noodling around with one particular function a wee voice popped into my head and said “Lexical Time”… which made no sense but sounded cool, but before I got any further it said “temporal lambda” which did sound cool…and also made sense.
The idea that came unbidden with the voice is that you could define functions which only evaluate their body when they meet a certain time condition (or temporal condition so we can sound fancy!). One example of such a condition would be BEFORE.
I must stress that I have no idea how useful these things may be, only that they sounded interesting. So with a little help from a great friend, I created temporal lambdas.
The first thing I am using them for is actually for the input control that my brain wouldn’t let me look at before (It clearly had a plan!). Key combos are very common in games for example you may have to press “A B A B <- ->” within 2 second to perform a special attack. With temporal lambdas, is really easy as it takes care of the ‘within 2 seconds for me”.
The key combo checker could be created like this:
(let ((key_cache nil)) (ct:tlambda (make-time-cache) (make-withinp 0 2000) (key) (setf key_cache (cons key key_cache)) (equal key_cache '(:left :right :b :a :b :a))))
So the programmer only needs to focus on the code to accumulate the keys and check if they are valid, and the temporal lambda makes sure that it will only be valid within 2 seconds (2000 milliseconds)
I’ll hopefully post some videos soon, once I have some control code written, so you can see what I’m yapping about.
I’m also just excited to see where temporal lambdas will be useful, again the idea came out of the ether so I don’t have a real plan for them yet. However if/when I do I will post up whatever I find.