PHP, JSON and the Twitter API: Timelines

As part of the prototyping for tweetfall I’ve been building various tools to interact with the Twitter API with PHP.

How long this demo will work for I’m not sure as the recent changes to the Twitter API usage will affect our game considerably so we’ll be re-designing it – more on that later.

Anyway, for now here’s a little Timeline browser I’ve written that uses the ‘1/statuses/user_timeline’ Twitter API method

You can change the twittername on the URL to view other timelines, or just branch of mine 😉

Dates in PHP and MySQL: Converting and Creating the MySQL datetime value

Working in PHP and MySQL is easy and you’re likely to be doing things with the datetime type a lot! Dates can be a little of a hoary issue, particularly the timezone aspect, but they are pretty straightforward.

Here’s a quick crib sheet I use with devs new to PHP and MySQL

1. I want to create a datetime string for use in a MySQL statement
// get the current date time and convert to a mysql datetime format
// the php time returns the current time in Unix epoch timestamp format
//i.e. the number of seconds since January 1 1970 00:00:00 UTC

$mysql_date_time = date("Y-m-d H:i:s", time() );

2. I want to convert a MySQL datetime row field so I can use in PHP

// take an mysql datetime and convert to the epoch based integer

$epoch_date_time = strtotime($mysql_date_time);

// now you can do what you like with it, convert it back to a user friendly date
// or use the int to do < > comparisons
// you should/could arguably do that in SQL

3. I want to convert the MySQL datetime to something user friendly for display

// convert epoch time to user friendly display
// see this page for more info
// this produces something like Friday 31st August 2012 09:46:02 AM

$friendly_date_time = date('l jS \of F Y h:i:s A', $epoch_date_time);

Packaging Revisited:

In August 2010 I wrote the following rambling on game packaging (below) and I wanted to revisit it with a Poll:

[polldaddy poll=6494369]

Over the past few days I’ve been swapping Atari 800 related tweets with @jazrignall ( & @RetroGT ( Joust and Dropzone being two classic games we’re quite misty eyed over.

Jousting makes me feel good.

To give myself a slight break from banging my head against geolocation APIs I dug out my old Atari 800 and put in the Joust cartridge. I’ve not actually played Joust since I was a teenager so I was floored to find that it’s still massively playable. Not just through my rosebud tinted glasses either. It really is a phenomenal game. Fast, frantic and lots of fun. In fact, I’ve just played for about 20 minutes which is about the same length of time as I played Joe Danger for yesterday.

I love Joe Danger but one thing I noticed, when I paid my £9.99 for it, was it didn’t come in one of these:

This is Joust in a lovely box. You should play this now. It’s 18 years old and still amazing.

Like the music industry, digital downloads (and their corresponding can of DRM worms) are quickly replacing the physical format. I miss the boxes but this isn’t a lament for the LP or gatefold sleeves, it’s really more aimed at the economics and philosophy of selling goods. It’s hard to charge money for something that has no physical form or rather it’s hard to persuade people that the invisibile item has comparable value to the same product that has physical form. You can, but it’s more effort than having it in box and I miss the boxes. For example, I still buy CDs becauase I like the artwork and sometimes, ironically, they’re cheaper than via iTunes.

To the left of my desk is this slightly random collection of games from my larger more random collection:

Some games on my desk

There’s been a gradual evolution toward something homogenous which ultimately lead to the tiny little itsy bitsy SD card (bottom of picture, actual size) which my purchases are now saved to. The SD card is very smart in terms of the vast amount I can store on it but it’s dead to me on an emotional level.

Take the bottom item for instance, Obliterator by Psygnosis, almost totally style over content. The game looked great, played like a dog but I didn’t care, it came in a massive box that looked like a prog rock album (actually they used Roger Dean a lot who did Yes’ sleeve covers). Sitting on top are two of Ultimate’s classic games. Jetpac is in a normal cassette cover and underneath sits Sabre Wulf, the first game they charged £9.99 for (Jetpac was £5.99).

Ultimate justified the higher tag primarily by sticking it in a bigger box with better artwork – the game of course had to be of greater quality too. Perhaps as the quality of the games improved packaging became less important as a way to differentiate the product. But to the person shelling out their hard earned cash, I think it still has importance, but maybe I’m crazy as I prefered to buy Valve’s Orange box in a store rather than over steam.

Does packaging add weight to the product or is it just an additional expense that we should jettison?


[polldaddy poll=6494369]

Javascript: Arrays, getting a random element from an Array in Javascript (a bit like PHP shuffle)

Building out the RPG game, I have a shop that is situated in a room that only sells one item and I wanted that item to be taken from random from a list of possible things it could sell.

So i thought the simplest way was to have an array of all the things it could sell and then pick one out from random.
Unfortunately, Javascript doesn’t have the lovely PHP shuffle() function which returns the array with its elements ‘shuffled’ which actually I don’t usually want – I usually just want one at random.

So here’s what I did to achieve the same thing

sprite_heroes = new Array('mario','sonic','turrican','tron','rockford','pitfall harry');

random_hero = sprite_heroes[parseInt(Math.random()*sprite_heroes.length)];

// hopefully it's self-explanatory
// but if not, all I'm doing is using the Math.random() method and the array's length to generate a random number
// between 0 and the number of items in the array

// or as a function

random_hero = lucky_dip(sprite_heroes);

function lucky_dip(your_array) {
return your_array[parseInt(Math.random()*your_array.length)];

// or as a prototype on an array
Array.prototype.lucky_dip = function() {
return this[parseInt(Math.random()*this.length)];

Games and why we play

As I’m building out this game company I’ve been bumping into old colleagues and on being asked what I’m doing now I often get the sense they’ve no idea why. Or rather, they’ve no idea why I hold games in such high regard, why my fondness for them goes far past any nostalgia and why I’m stopping working on enterprise web applications (which I’ve been doing for the last 16 years). I can see their point initially, Enterprise software can be very lucrative. It’s also insanely dull. It certainly tests your motives for working.

But for me it’s as simple as this. Playing video games lets me keep the child in me healthy. The child in me is the part that wants to be friends with the world and it’s the part that thinks anything is possible. I’d be a lot poorer without it.

So games, they give me a break from the part of my brain that wants to analyse things and hands the reigns over to the part that wants to run around and explore and believes that you really can fly if you’re holding a feather.

Ramblings on Game Platforms, HTML5 and Payment Fragmentation

PS3, Mac, HTML5/Flash, iPhone, iPad, Droid 4.0, Xbox360, Wii, DS, PSP and PC. I play games on each of these platforms in pretty much that order. It’s a frightening amount of tech devices when you see them written down and/or scattered throughout my house.

Is it too much? I think it is. A cheap (and likely ill thought) comparison with other entertainments would be the music, television and film industry. To consume media from those industries doesn’t require an arsenal of tech that resembles the bunker scenes from Wargames like gaming does.

Don’t get me wrong, I love the variety and as a gamer who remembers the Christmas I got an Atari VCS/2600 in the late 70’s it’s amazing. But as a developer building a game company it’s making wonder which platform’s the best target and specifically if HTML5 gaming can support itself.

This past week I’ve played Renegade Ops, Infamous 2 and completed Dead Space 2 on the PS3, played through Cave Story+ and Bastion on the Mac, Super Goat Wars on the iPad and Cavorite on the iPhone. What’s interesting is that I only paid specifically for the last 2 as item purchases on iOS as I used PSN plus and bought the Humble Indie Bundle to ‘play’ the former games. As an aside, I wonder at what point we’ll see the same discounted/grouping approach on iOS?

The bottom line there is I didn’t pay very much (perhaps £15) to play, what I consider to be, some of the highest quality games I’ve ever played. With PSN Plus it’s unlikely I’ll ever buy a PS3 title off the shelf – that could be down to my age and the fact I’ve become a little unmoved by marketing frenzy. What’s scarce isn’t money but my time to play all these great games – a subject covered by much smarter people elsewhere.

Gaming, for me, has become a Vegas-style all you can eat buffet and my concern is how that affects the developer. That is, how much of the money trickles down to the developer and does the developer choose their platform based on the demographic of the platform or build their game around a platform’s ability to maximise the profits they can get from it?

To help get some data on the subject I’m going to try and get a bunch of developers from the various platforms to take part in a Q&A session…maybe GameCity Nights could help 😉 ?

So first up, would you pay to play an HTML5 game or is there nothing of ‘value’ at the moment?

[polldaddy poll=6457783]