ajh1138

Archive for the ‘Programming’ Category

Cocoa/Objective C development tips for .Net Folks: Part I

In Programming, Uncategorized on October 1, 2009 at 3:41 am

No, this isn’t about using .Net to make iPhone apps!  It’s just a set of observations that might make it easier for people like me who currently use .Net (specifically, ASP.Net) at work, but want to start fiddling around with some Objective C, Cocoa, etc.

Keep in mind that this is from the perspective of someone who got into web development without traveling down the formal education route (when some of my buddies were learning C, COBOL and PASCAL in CompSci 101, I was sucking sand through a gasmask, patrolling some godforsaken ammo dump or airfield in the middle of nowhere).  I have no pure C language knowledge or insight, so all of this stuff is new to me.  I know many web developers in the same situation, so maybe this will help some people make the connections between Obj C and the types of languages they’re used to.

- “Actions” are event handlers.
- “Outlets” are properties that can be bound to your user interface widgets.  They are objects of the same type as the given widget. So if you have a RoundedButton on your UI, you’ll probably have a RoundedButton in your .h/.m code if you want it to actually do something.

From what I can tell, you don’t need to name the specific buttons in the UI part…you associate the button with its corresponding outlet via a drag-and-drop in the UI editor (“Interface Builder”).  I’m pretty sure you can do it manually/dynamically via code, too.  In the .Net world, you’d set the name of the button in the UI editor or in your HTML code, and Visual Studio would automatically make the corresponding code additions.  I haven’t seen that ability in XCode/Interface Builder, but I’m totally new to this so don’t take it to mean that it doesn’t happen.

You can think of the .xib file (known as a “nib” file by Cocoa vets to honor the former file extension) as needing a code-behind page.  The nib is your UI, and the .h and .m files need to be told “Hey, I have these do-dads on the UI.”  After all, if you dig through the code that ASP.Net automatically generates, you’ll find the same kind of definitions for each UI item in the code-behinds.  Same-same.  Don’t let the EXTREMELY WEIRD BRACKET-HEAVY SYNTAX scare you.

Speaking of which, here’s a brief bit of learnin’ about the syntax.  Let’s take apart this function…

-(IBAction) openThing: (id) sender
{
// code that does stuff
}

The hyphen is there on purpose.  (Don’t ask me why.)  (IBAction) is the return type, openThing is the name of the function.  (id) is the type of the argument and sender is the argument itself.  To call a function, use brackets like this:
[myObject doSomething:5];
myObject being the object, doSomething is the function being called, and 5 is the argument.

By the way, the “id” type in Obj C corresponds to Object in our world.  It could be anything.  You’ll need to cast it to whatever type actually sent the event if you want to use it.

If you ask me, the brackets clutter up things, and dot notation isn’t supported enough in Objective C.  They added it to 2.0, but I think it could be used more than it is.  You still need to use brackets for functions if I’m not mistaken.  Of course, you can’t just change the entire syntax of a language without peeving your developer base!

On a side note, I’ve found XCode to be a sweet IDE to work in.  At first I found it a little annoying to have to switch between two completely separate programs to do coding vs. UI work, but then I realized some benefits to it.  Unlike Visual Studio, you can open up just the stuff you want to work on.  VS gets more bloated and resource-hoggy with every iteration, and it would be nice if you could completely rip out the Design mode when you’re working on ASP stuff.  You know it’s lurking in memory somewhere, ready to reformat your clean, hand-written tags the moment that you accidentally summon it.

Another advantage to having two separate programs is that it reinforces the separation of concerns between code and UI.  This premise lies at the very heart of how iPhone programming works – it uses the Model-View-Controller pattern!  I have used this pattern extensively, and although I’m not a design patterns guy, I have to say that it makes for fairly clean distinctions between the various pieces in an app.  If you haven’t used it yet and you’re an ASP.Net developer, you’re in luck.  ASP.Net has an official MVC implementation!  Grab it, build some stuff with it.  Understand it. It’ll help you see how things work in the iPhone (“Cocoa Touch”) world.

The books I’m reading on the subject are Beginning iPhone 3 Development by Dave Mark and Jeff LaMarche, and Programming in Objective C 2.0 (2nd Ed.) by Stephen G. Kochan.  I’ve found both of them to be very, very good books.  I will say that getting about halfway through the Objective C book first will make your life a lot easier.  I’m currently switching back and forth between them.

I’ll be posting more stuff as I wrap my head around this.

Hauler v.004a – Combat system and swanky logo added

In Game Dev, Programming on August 5, 2009 at 3:47 am

Hauler v.004a is available for immediate play.  That’s right, it’s a fully playable game now!

I’ve added the combat system, which was a lot of fun to design.  There are two pirates that can attack your ship, and you choose to fight, flee or surrender during each turn.  The player is punished/rewarded with varying severity based on their actions.  For example, if you surrender the pirate only takes 1/4 of your cash and a random cargo item.  If you attempt to flee, you could lose up to half of your credits and all of your cargo – or you could escape with no penalty.  If you fight and lose, you lose all of your cash and cargo, then your dad sends you 1000 credits to start over again.  If you win a fight, you get a good chunk of cash and your available cargo space is filled with a random trade item.

With this version you’re attacked EVERY TIME you jump to another location. This is so that people can test out the combat system.  It’s not balanced yet, so both the player and pirate tend to miss shots a lot.  I also need to have a visual display that shows the player their remaining shield strength, firepower, etc.

Hauler004_combat

The big purple square is where the pirate’s image will go.  I’d like to have the pirate’s dialog look (and sound) like the dialog from 8-bit games (a’la MegaMan, Legend of Zelda, etc.) where the text comes out one character at a time and makes a little noise.

I need to spend a day going over the visual aspects of the game and do up the buttons, etc. all 8-bit style.

The game’s settings are entirely XML-based, including the pirates’ scripted dialog during the combat parts.  I refactored the combat script/interaction method a couple of times while I was working on it, and actually wrote the XML before I started coding.  I usually try to get at least a basic data structure figured out before I build the application layer.

I have also bodged-up a swanky logo for the game.  It’s based on the classic Mudflap Girl, but with a sci-fi twist.  The chrome needs some help, but I’ve had this logo idea banging around in my head for a couple of weeks and just had to see it for realz.

HaulerLogo1

The feel I’d like to get is a gritty, long-haul trucker culture and environment.  I’m no graphic designer, but I’ll do the best I can.  For this project I’m stretching my visual talents and it’s important that I do it myself.

CrystalDecisions.Web – could not load assembly, etc.

In Programming on November 17, 2008 at 6:17 pm

VS 2008 givin’ ya grief cuz it can’t find that nifty Crystal Reports viewer?  You need to install Crystal Reports Basic 2008!  You know…the one that is supposedly packaged with Visual Studio 2008?  The “embedded” one?  Yeah!  That one!

Here’s where I finally tracked down my copy:
https://smpdl.sap-ag.de/~sapidp/012002523100009351512008E/crbasic2008sp1.exe

That long string of numbers + E is probably a session number or something.  If it asks for an identity, just smile and nod and click OK.  Why they put free stuff under an https site is beyond me.  But then again, so is the fact that I have to go to some German website to download something that’s supposed to come with my IDE.

I really had to dig for this one.  Some folks might be lucky enough to have an installation file in “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5″, according to this thread on MSDN.

There’s also “C:\Program Files\Microsoft Visual Studio 9.0\Crystal Reports\CRRedist\IA64″ but  I ain’t got one of them fancy 64 bit processor doodads.

ORA-01036: illegal variable name/number parameter in ASP.Net app

In Programming, asp.net, sql on October 23, 2008 at 9:12 pm

My Oracle chops are way outdated, and, being a fan of business objects and/or a genuine Data Access Layer, I’m not used to working with typed datasets in asp.net.  So when I got the above error I was pretty stumped, and I started using some obscene anti-Oracle phrases to name a few test variables to figure out wtf was going on.

Eventually I figured out that it’s not a good idea to just enter parameters into a Select method via the Properties window, even though Visual Studio will cheerfully let you do that.  If you don’t have the parameter referenced in the actual SQL of the select method, you’re gonna get the above message when you try using it.  So…

In your Select method’s SQL, be sure to add “WHERE ID = :ID” and Visual Studio should pick up on that and make a parameter for you.  Too bad it doesn’t work the other way around.

When I was trying to find info on this error I found lots of talk about update parameters and other causes, but didn’t see anything related to this particular circumstance.

Run multiple instances of Second Life for easier scripting

In Programming, Second Life on October 4, 2008 at 5:02 am

When I’m programming, I love it when I enter “the zone” and the code just flows from brain to computer.  In Second Life, nothing breaks that flow like having to minimize my script windows and Edit dialog, and then having to fiddle with my camera to get a look at how my script is affecting the object I’m working on.

Here’s a little tip for anybody who, like me, has about twenty LSL script windows open in Second Life at any given moment.  If you want to grab a quick peek at the object you’re working on try this:

Run two instances of SL!  Keep your alt’s screen tidy and centered on the object you’re fiddling with.  When you want to take a look at your scripting handiwork, just Alt-Tab to switch between your scripter and your alt.  This is really handy for folks with multiple monitors.

To run multiple instances of SL, you’ll need to modify your Second Life shortcut. Right-click on the shortcut and go to Properties.  In the Target textbox, just add “-multiple” to the end (no quotes).  Make sure there’s a space between whatever is already there and the hyphen.

I advise you to rename the shortcut to “Second Life – Multi” or something like that, because subsequent installations of SL will overwrite your icon if you leave it just “Second Life”.

Happy scripting!

* PS: A word of warning…I ran two instances of the Release Candidate so I can compile scripts in Mono, and I encountered a really strange permissions/ownership glitch wherein my alt got permission/ownership of an object, while my main toon lost permission/ownership.  I suggest running the alt toon with the standard client instead of the Release Candidate.  I’m reporting the issue to the proper authorities.

What I Learned Today – 30july2008

In Programming, What I Learned Today on July 30, 2008 at 7:27 pm
  • A LinkButton in ASP.Net has both an OnClick event and an OnCommand event.  The OnClick event expects your typical EventArgs, while the OnCommand event can receive CommandEventArgs.  I was about to go nuts trying to figure out how to convince my app to use CommandEventArgs in a regular OnClick event!  I was like “If I can use CommandName and CommandArgument in my LinkButton tag, HOW THE HELL am I supposed to get them fed into the click event!!?!?!”  Well, now I know.
  • If you’re using a GridView to display a list of items, you can use Container.DataItem.Index to display the items’ index in the collection.  It probably works with other things like DataGrid, etc.  You can also use it as an argument, thus: <asp:LinkButton … CommandArgument=’<%# Container.DataItem.Index %>’ />  – remember that it’ll come across as a string or object in the argument, though.  Just do an int.Parse() or whatever.