Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts

Monday, April 4, 2011

Learning While Coding

The last week or so at work has had me learning how to do some things for when I program which I never expected. They are all things that are important things to be able to do, and a few aren't as difficult as one would expect, though the major one (which I will get to) has been giving me utter headaches, because it leads to a rather large change in programming style and way of thinking.

Warning, heavy geekery ahead. Though really, on this blog, would you expect anything else?

To begin with, Localisation of applications. This is quite a big thing on, well, any piece of software. How do you write a program to work in any language? To make it display properly in Japanese, Chinese, Russian? Apart from the obvious issue of needing someone to translate for you (if you do not know the language), you also need a way to make it easy to inject these language options into your software. For example, if you hardcode all of your strings, then for every language version you need to find where all of these are coded, then change them for each language, then recompile many different language versions. This is completely unmanageable!

Luckily, for me at least as an iPhone programmer, Apple have made it easy. It seems so alien to me, having something from Apple which simply works for a change (my work laptop is living proof to me that the Mac elitist pricks who tell me that Macs are superior to PCs simply are spending too much time staring lovingly at the form of the computer, rather than the fact that the screen is showing that all your apps have frozen)!
To localise an iPhone app, all you need to do is create a strings file (called Localizable.strings - remembering that its z is important because they're American and can't spell. Also, a lost of configuration stuff is skipped by using this particular filename, since its the default), and define a bunch of variables in there. Once you have done that, wherever you code a string in the app itself, replace with the following piece of code:

NSLocalizedString(@"TITLE", nil)

where "TITLE" is the name of the variable, and the second parameter is simply space for a comment to assist a translator with (context matters a LOT in language).
Of course, there is a little bit more to it - you still need to actually localise your strings file. In xCode 4, all you do is go to the localise panel on the right, and add a localisation to your strings file. It asks you what language it is for (since the iPhone will use default language settings based on what the user picks). Then, simply change the variables you set in the above one to the language specific strings. Sorted!

It gets slightly more complex when you are localising images and interface layouts (due to button sizes and things), but this is the general workflow of it. Not bad at all!
(Also, Ray Wenderlich's site is where I found the tutorial that taught me this. Awesome site full of tutorials. Don't freak out when you see the "I'm quitting iOS" post - its an April Fool's troll)

 
Unrelated: Rocks fall, everyone dies

Another important thing I've been learning as part of work the last few days has been how to use a Unit Testing framework for the iPhone. Unit testing is an important part of programming. At least, that's what I've heard - I've yet to see results from it, because all I've been doing is learning how to do it, how to combine it with Mock Objects, and trying to get my head around this enough to write some useful tests.

The theory behind it is that if I write a test that ensures I get correct output from a function I write, then later on if I change the function (refactoring, optimisation, etc), then I can rerun the tests. If the tests fail, then obviously I've changed something to the point where it breaks - aka failed refactoring, where the actual processing has changed. Sounds useful huh?

Well, even more than that, once I've caught up on the tests I should have been writing, I can use this for TDD - Test Driven Development. This is where we write the tests BEFORE the code is actually written. The purpose of this is to force me to think about what is actually needed (in terms of variables and functions), and then ensure that each function works before I move onto something else (since its always nice to see green lights as irrevocable proof that your code works).

As you can probably tell, this is a far cry from my usual method of "think about the system, design some objects, start writing, run the app to see if it works". Hopefully, this'll work much better.

Its just doing my head in at the moment.

I won't go into details on how to get it working on the iPhone, since there are many ways to do it (and this post will go insanely long, and overly technical for those not so code minded), though I will mention that I'm using GHUnit-iPhone for a test suite, and OCMock for the Mock Objects, if you are interested in taking a look.

I will probably integrate some of this onto my home machine so I can work from home if required - and possibly more importantly, for my own work (which has yet to begin / be designed).

Monday, February 14, 2011

Games Games Games

Americans get to play Marvel vs Capcom 3 very soon. Like, midnight tonight in whatever stupid timezone they have. I hate you, America. Give me my game already. Grrrr.
I've already decided two thirds of my annihilation party as well (character usefulness notwithstanding) - Dante and Deadpool. Mainly coz they're awesome. The third could well be Viewtiful Joe, or Zero, creating a team entirely of RED.

A friend gifted me Monday Night Combat on Steam the other day. I haven't played any of it beyond the tutorial - but that part was at least fun. It kind of has a Team Fortress 2 feel to it, but making it third person, and allowing for single player defence of the money ball. Tonight, I'm totally gonna give it a bit more of a play.

I haven't touched WoW in at least two weeks. And somehow, I don't miss it. Until I realise that I still haven't quite hit level 85. I don't know, I want to hit level 85, but there are many other games to be playing at the moment.

I prepaid for Dragon Age 2 on Steam. I still haven't played much of the first one. Well, scratch that, I played it for a fair while, however this consisted of replaying the early stages of the game repeatedly. I believe I have completed the Mage origin story and the Ostagar Castle segment of the game at least 4 times now. I have been besieged with horrific luck with this game - one time losing my save and having to start over. Another time finding a weird glitch where it would always revert my save to be inside Lothering again, then upgrading my PC and losing content due to that. Eventually I'll finish it.

Damn, I want Marvel vs Capcom 3 now. NAO I SAY!

I bought a strange little game on the iPhone on Sunday. It's called Dungeon Raid - and combines a puzzle game with an RPG. This is a combination I thought I would see the last of with Puzzle Quest (and my clone of it in Game Dev Story). I thought wrong. It works quite well, although for some reason I still cannot top the score I got on my first play. There's got to be something wrong with being able to get a good score on your first play - and then being unable to repeat it when you understand how the game works!

I also found Devil May Cry on the iPhone. This makes me happy, except for the part where it didn't work - it froze. I then read reports that it worked if you turned WiFi off and were patient with the seemingly frozen load screen. I tested that this morning - lo and behold! The game works! Due to being at work, I didn't actually play the game, but that's likely what my trip home will involve. Or maybe just more Dungeon Raid. Or Final Fantasy Tactics...

I seem to be reaching the late sections of Final Fantasy II. Again, playing this on the iPhone. It was much cheaper to spend $5 or so on the iPhone for it, than to track down and spend $50 on the PSP version. Totally worth it - and the game works just as well. I think its actually identical to the PSP version, so go for it, if you get the chance!

I want to play some Final Fantasy XIII, but my girlfriend just bought a PS3, and wants to play it together. So I'm waiting for her to catch up before I play again. Couple this with staying at her place for the next week and a half starting on Thursday, and I won't be touching the game again for a while. I'll probably forget how the battle system works (again) by the time I get back into it :P

Where's my copy of Marvel vs Capcom 3? :(

Sengoku Basara: Samurai Heroes is fun. Don't expect a sophisticated game though - it is literally the Dynasty Warrior / Samurai Warriors engine with some tweaks, and shiny graphics, and superpowered samurai. Its still good fun to play as Date Masamune, slashing people up with six swords (all at once, held between his fingers. Yes, he fights as if he's Wolverine, but with swords instead of mere claws).

Ooh, Bulletstorm and Deus Ex: Human Revolution appear soonish! I played Duty Calls, the Call of Duty parody that was an ad for Bulletstorm. Quite a funny game, if you can't afford the 700 MB or so download, then watch the video playthrough at the very least.

I just lost The Game.

Quite sad news that Guitar Hero has officially been killed by Activision. Though interesting that Harmonix plan on pressing ahead with Rock Band. Maybe that means we'll see some of the pro instruments in Australia?
Yeah, as if. That would imply that American game companies saw us as an actual market, rather than a strange sized dump on the southern end of the planet.
I wonder what'll happen to DJ Hero...

I want Marvel vs Capcom 3 gah it hurts just sell me the game already!