Welcome to my Programming Blog...

I am currently working on a couple of projects: An original game called "Implosion" which I am porting from Flash to the iPad, and a remake of Q*bert in Python (pygame), as part of the class I am teaching. Please feel free to use the "Labels" (at right) to follow a specific project or theme. If you are one of my Python students, I recommend that you check out the Python thread.

Tuesday, April 27, 2010

Ah, the memories...

Boy, my C is rusty.

Last night, I was working on the Implosion project with SIO2. I am still fighting with the C++/Objective C interaction. My problem last night was that in my Objective-C class, I had an array of NSString objects. I needed to select one of these strings and send it to a method in SIO2 that was expecting a C-style "char *" variable.

It wasn't hard to find a method in NSString called "UTF8String" that does a conversion - but it converts the NSString to a "const char *" string, instead of a "char *" string. And this is where I got bogged down. This is all C/C++ code, and I haven't done that in a few years. The const keyword meant that the string can't be modified, and although there were some sites on the web that suggested that I cast it as a non-const variable, I really don't want to modify the original string in the NSString variable - I will need it again!

Eventually, the magic typing monkeys in my computer that make up the Internet gave me a series of websites that brought me closer and closer to the answer. I ended up at a site that gave me the final piece. Here is what I wound up doing:

    const char* tmp = [typeString UTF8String];
    char* typeCString = new char[strlen(tmp)+1];
    strcpy(typeCString,tmp);

... and that worked just fine. With this, I can make multiple shapes in a 7x7 grid. I have two new short-term goals:
  1. In blender, I need to reduce the size of the shapes (again) - they are still too big and overlap each other. (I also need to make sure that the triangles are centered on their own local origin.)
  2. I need to find a way that I can make the chips "fall" in when a chip is removed.

No comments:

Post a Comment