Sunday, February 27, 2011

State of hmmm...

I didn't do one thing on my app over the last 1 week and 1 day. But I actually have a good reason. I was developing a new website for the bookshop that my wife and I own. We decided to buy into the e-commerce solution that the American Booksellers Association (ABA) offers to its members. The price of opting into their solution used to be too cost prohibitive for the ROI (return on investment). We're a tiny shop and our "fan base" just isn't that rabid, so once the e-commerce solution goes live I doubt we'll make that much from it, but at only $100 a month to use it, it was too inexpensive not to try. Previously, they charged a setup fee and the monthly was $250. Also, they now offer Google ebooks, so that was the primary reason I showed renewed interest.

So for the last week I've been using all of my free time to develop the website: thebookerynook.com (feel free to buy an ebook from us!).

Okay, back to the game. I abandoned my latest idea (there were buckets and witches and stuff). I still like the idea and will try to pursue it later. But as I was developing it, and had most of the game-play finished, I realized the rest of the game was too big for me at this moment. It would have been along the lines of Angry Birds. So I would need to develop 20 scenes per level with high scores and the ability to go to any already-completed level and ... well ... it was overwhelming. So I backed up and thought about a game or an app that would be "easy" to do. Where "easy" means no scoring, no levels, no worrying about getting scores up to Facebook, etc.

I did a lot of brainstorming by myself and with my wife. One idea I've toyed with before and came back to here was a maze. I assume mazes have been done and, quite frankly, I wasn't sure how to have a real maze and keep an avatar centered along the walls of the maze as a player moves it around with their finger. But the idea kept bubbling up until I married it with another idea: board games.

I've decided to build a game where the player cannot see any paths, just squares and as they travel, trying to find their, way, obstacles (ala a board game) pop up, sending them backwards, sending forwards, sending them to a different area of the board. And, you know, so on.

Sunday, February 13, 2011

Annnnnd ... action!

I have the very basics of the game finished: user can move boards (platforms) around and then pour water to melt the witch. There is definitely some refining to do. However, I need to start building the "game" - the levels/scenes/etc. So I'm going to start learning Director class. I'm still not sure of all that it does, but from reading the forum or it, it seems like a good backbone for building a game. You use it to define

I assume the name "Director" is just something that the developer (Ricardo Rauber Pereira) decided to call it. I also assume that class is specific to either Lua, Corona, or more likely, programming in general. So let me search the Great Big InterWeb to see what I kind find for the definition. Be right back.

Okay, "class" has at least two possible meanings. In OOP (object-oriented programming), a class is a category of objects. The example the Web dictionary had was a class named "shape", and in that class you have objects (along with their properties) of circles, rectangles, squares, and so on. In .NET languages (no idea what these are, has something to do with Microsoft), a class is a template.

The Director class in Corona seems more like a template, but you also define your objects. I think classes in Corona are APIs on steroids, containing functions and object descriptions.

Tuesday, February 8, 2011

Can't touch this

It's amazing how many blind alleys I enter when trying to program. Because I don't know how Lua or Corona really work I spend a lot of time and energy pursuing thoughts only to find, eventually, that I just can't get it to work that way. Spent the last two days trying to figure out how to enlarge a touch area. When I tried my game on my Android phone, the pieces were so small that it was very difficult to focus on them and drag them (or activate the bucket to pour the water). So I went to the forums and found something that might have worked: you put a larger, invisible rectangle in front of the small object. Worked great with the bucket, not so great with the boards that you drag to direct the falling water. I used display groups to link the rectangle and smaller object.

A group is like a bag and you can put your display objects into that bag so you can do things to all of the images at one time. It's a way to organize and a way to manipulate your display objects (images). Problem is, once you group them the physics engine in Corona doesn't work very well. So after I grouped the small board with the larger invisible rectangle, I could move them easily, but the water balls fell right through.

And that's when I tried different things. Tried to weld the two objects together. After wasting an hour or two I find out that you can only weld "dynamic" objects together. Well, a dynamic object reacts to the gravity of the physics engine, so the board and rectangle fall to "earth" and can't be moved to a specific area.

Then I took a detour through waste-your-time-ville and for some reason thought it would be a good idea to remove the physics from the target object. You see, I had the target object set up as a physics body so that when the water balls hit it I could have the object melt. That was working fine before, I have no idea why I decided it would be better to get rid of that. So I spent hours trying to make the code work in a way that it can't (or, more exactly, in a way that I don't know how to control it).

After a frustrating two days I find myself no further along. However, as others have said, there are no mistakes, only lessons to learn. I have learned more about coding and how Lua and how Corona work (and don't work). So that's something.

Sunday, February 6, 2011

It's just like starting over

I spent this week starting over. I scrapped everything I had because I only vaguely understood part of it and didn't understand other parts at all. I then began to recreate everything one piece at a time, using it only when I understood what the piece did.

So I'm pretty much back to where I was before I scrapped everything ... except with a much better understanding of what's going on with the code. I take that back. I'm ahead of where I was.

OH!!! I also built my "game" and ported it to my Android phone ... and the "game" works!! "Game" in quote because all that happens is: you touch the bucket and tiny balls fall out and hit their target and make it disappear. But I was very excited. Also found out that you have to port your .apk file (an Android app) to an actual web address to download it. I tried using Google Docs. I was able to download it to the phone using Google, but the phone was at a loss as to what to do with it. Now I have to figure out how to delete that file from my phone.

So, all in all, it was a pretty good week. I still have a long way to go, but the progress is good. Today I need to add multiple buckets (lives) that automatically pop back up after a bucket is used, need to add movable platforms back into the game (these divert the tiny balls), and also make the "game" able to restart itself at the end (right now after one bucket of tiny balls the game is just over and sits there).

Okay, maybe I won't get to all of that today. But it's certainly manageable by next weekend.

Monday, January 31, 2011

Pretty shiny buttons

Okay, I read a bunch of the Lua 5.1 Reference Manual, but then I found a different guide: Lua for Beginners. And it really is for beginners ... yay. This would not be of much use to a seasoned coder just looking for the differences between whatever language they know and Lua. But it works great for me. The guy who wrote it is German, so expect a stilted English, but mad props to him for putting this together (I think back in 2006).

So I started on page one and read. And read. Did some exercises. Read some more. And I understood more. After reading over half his "chapters" (they're very short), I went back to the Corona SDK website (I found out today that there's a difference between the Corona SDK and the Corona Game Something-or-other. Maybe they've been combined, I don't know, but I'll have to look into whether I'm using the correct stuff), and looked at some more sample apps. They actually made more sense. I'm starting to figure Lua out. Of course, after looking at several apps and their complexity I felt a bit discouraged because I'm still no where near being able to do some real coding. But ... baby steps. Tough for me because I'm so impatient (and easily discouraged).

Having emptied out my main.lua file, I created a button in it:

    local bucket = display.newImage( "bucket.png", 45, 20 )

Okay, actually, I displayed a PNG graphic. But it's also my button. After learning more about events today, I made the button turn on its side when you click it:


    local bucket = display.newImage( "bucket.png", 45, 20 )

    local function turnBucket( event )
    bucket:removeSelf( )
display.newImage( "bucket_pour.png", 45, 20 )
    end

    bucket:addEventListener( "touch", turnBucket )

So what did I learn today (besides this?). Well I learned that "touch" is an event name reserved by Corona to indicate that someone has touched the screen of their mobile device. Before today I didn't know if "touch" was a user-defined variable like bucket or turnBucket above. I also found where a bunch (or maybe all) of these Corona-defined events are listed.

What I didn't learn was why the word "event" is between the parens after turnBucket. The chunk of code above worked with the word "event" and without it. I shall go do some exploring and see if I can find the answer.

Second only to learning to code, is learning where all of the resources are. The more I look, however, the more confident I feel that all the information I need is out there ... I just gotta find it.

Sunday, January 30, 2011

What I don't know, Part II

This post began with: What I don't know

I find something new every day. Today, just seconds ago, it was the Corona Project Manager v2. I went ahead and bought it as it looks like it'll keep my projects organized for me.

Okay. Back to coding in Lua. Back to reading the guide. And ... wow. Lost again. I need Lua for Dummies, obviously. It was trying to explain tables. Here's their first example:


  1  a = {}     -- create a table and store its reference in `a'
  2  k = "x"
  3  a[k] = 10        -- new entry, with key="x" and value=10
  4  a[20] = "great"  -- new entry, with key=20 and value="great"
  5  print(a["x"])    --> 10
  6  k = 20
  7  print(a[k])      --> "great"
  8  a["x"] = a["x"] + 1     -- increments entry "x"
  9  print(a["x"])    --> 11

So, in line 2 because k = "x", that means that in line 3 a[k] = 10 creates a value of 10 or "x". 

Oh, wait, no it doesn't. Did I just have a minor breakthrough? Think of the table as a set of cubbies (an array?) lying flat. The name of this set of cubbies (shown in line 1) is the letter a (this is the table name). You can label each cubby whatever you want (hopefully, in reality, you're labeling them with meaningful names). So in this example, you've labelled one cubby as "x". 

For awhile I thought k (in line 2) could also be the name of a cubby, but it can't. Can cubbies only be numbers or strings? The manual says: "An associative array is an array that can be indexed not only with numbers, but also with strings or any other value of the language, except nil."

But when I tried to use a letter (no quote marks around it), as an index (the name of a cubby):

   a = {}
   a[k] = 10
   print( a[k] )

I got a runtime error saying that the table index (cubby name) was nil. However, the text quoted above might be correct and I simply don't know that "any other value of the language" does not include letters by themselves (meaning letters without quote marks around them, which is called a string).

This leads me to this question: what does line 2 do? It seems to be a pointer to the real cubby name (index), which is "x". 

If you look into cubby "x", you'll see 10, because line 3 defines that. You could also set the object in "x" with:

   a["x"] = 10

Instead, you're using the pointer named k to actually fill in the cubby named "x". Remember, k CANNOT be the name of cubby (index). So why is k there at all? I'm really not sure. My guess is that you use it when your cubbies have long names (indexes). Otherwise, I don't know why you would ever use line 2 in your code. If the cubby is named (indexed as) "BloodDonorVolunteerName", you certainly don't want to type that behemoth over and over. So you, in essence, name the name. You name a pointer as bdvn to take the place of the actual name of the cubby (index) "BloodDonorVolunteerName". 

   a = {}
   bdvn = "BloodDonorVolunteerName"
   a[bdvn] = "Bob Thompson"
   print( a[bdvn] )


Wow. That was confusing and took a lot of time for  me to figure out. I suspect someone with a mind for coding would have this figured out long before I did. That's why I dropped out of computer science, my mind was having a difficult time wrapping itself around it. But now, 30 years later, I'm trying again.

Eesh.

What I don't know

Really, every post could have this title. It's 7AM on Sunday. The chihuahua is balled up in front of the heating duct, I'm trying to wake up with a can of Coca-Cola cherry zero (why does it taste better than Diet Cherry Coke?). I'm sitting at my iMac in the dining room.

And I'm starting over.

I just made a copy of my WIP (work in progress) folder. I'm going to delete everything out of the main.lua file. That's akin to the index.html file for the Great Big InterWeb. Every Corona SDK project has to have this file, even if all is does is point to all the other files that actual do the work.

I'm starting over because I've been cludging together sample code from a bunch of different resources and I got myself dazed and confused. So I'm starting from scratch and I'm going to rebuild everything I thought I had before. I'm going to try to understand all of the code I put into the main.lua file. That will be difficult as it's still confusing to me. I still don't understand the basics of the language and I haven't stumbled across that tutorial or forum post or whatever that really breaks it down for the true beginner.  So let's start. The file is blank.

I'm starting from scratch. I've opened the Lua 5.1 Reference Manual, written by the guy (or the folks?) who developed Lua. This is the first edition. There's a second edition for sale through (damn them) Amazon. [Of course, you want to try to buy local first. ALWAYS TRY TO BUY LOCAL if you want your local community to thrive. If you don't care about your neighbors and friends and family who live near you, then by all means, just purchase from Amazon and, without a second thought, send all of your money out of state.]

Ah, I've already learned that you don't have to separate statements with a semicolon. It's optional.

Okay, I'm going to stop here because this post is getting long. Continued in Part II of What I don't know.