Monday, September 8, 2008

Browser Inconsistencies: Part 2

Hey-o

Today was my first day at my new job. Exciting, but nothing notable yet. Hence, this is a relatively shorter entry.

Anyways, I was playing around with HTML and CSS again, putting together a chess/checkers-style board with HTML and CSS, and found another browser inconsistency.

I have a 4x4 grid of alternating white and black tiles. The tiles are arranged in rows, and there are tokens that are placed absolutely on top of them. The rows of tiles and tokens are all in a master div. The rows are each divs that have a clear: both property to make them cascade properly. At first, I didn't define the horizontal position of the tokens. In firefox/opera/chrome, you see the following:
















The absolutely positioned tokens are removed from where they "should" be, and are placed in the upper-left corner of their containing div (the white token has been defined to be that low). However, in IE8, this happens:















Apparently, if a horizontal position is not specified, the absolutely positioned elements stay where they would, even though they are removed from the box model. You can tell they have still been removed, because if they hadn't, then the border would be surrounding them as well. Setting the left: 0px; property makes IE8 render the same as all the others, but it is still interesting.

Monday, August 18, 2008

Browser Inconsistencies: Part 1

I did a freelance gig recently that required me to do some HTML/CSS. Like all web tasks, one of the primary concerns was browser compatibility. After several hours of cursing at IE and Firefox, I found a good php script that reliably detected browser, so I used that, but doing that always feels like cheating, so I'm going to be spending some time in the coming months playing around with CSS and HTML, looking at where the breakdowns occur. Here's my first post on the subject.

Surprisingly, when just messing around, it took a little while before I found my first break. I put two divs, one absolutely positioned, one relatively positioned, inside a larger div. The larger div was placed relatively at the top of the screen, and given the style "top: 20%;" What happened then? I'll show you.


















Surprisingly, Firefox was the one that did not register this style correctly. I'm pretty sure it is an issue, and not something laid down by the W3C. This is because when I changed the style to read "top: 20px;", both browsers behaved the same. Interesting.

Thursday, August 7, 2008

Little Bit of Good News

Apparently, my blog is the top hit for the search "add hidden fields programmatically" on Google.

Hooray!

Welcome everyone who's looking for how to add hidden fields programmatically. Please leave comments as to whether or not you found my entry useful!

Monday, July 28, 2008

Variable Scope Issues

Again, here's a new link to my latest project. http://www.cs.drexel.edu/~asc38/Projects/CdlC/
I think it's actually pretty fun, so I hope you try it out.

The only major issue left to tackle is the high score board. When the game ends, you can submit your score to the online scoreboard (I'm currently in first place, go figure.) It was a chance for me to play around with flash's internet communication abilities. It works pretty decently as well, if you ask me. The problem is that, for some reason, the scoreboard only shows up the first time you play it (per page refresh). What that means is that if you press the "Play again" button, play the game, end the game, and submit your score, you won't see the scoreboard. I'm completely scoobied as to why that is. The code to update the scoreboard is as such:

trace(event.target.data);
htmltext = event.target.data;
scoreBox.htmlText = htmltext;

If you're not familiar with flash, trace is a command that outputs things to a special "output" window. Therefore, the event.target.data variable should be shown on my screen. The problem is that despite the fact that I do get the correct text outputted to me by the trace call, the scoreBox.htmlText doesn't reflect what it was given on anything other than the first time through the game. I had a similar issue (in fact it was the only real major "bug" in the first iteration) with the images from the last scoop being present on replays as well, and that was fixed by making sure that everything was reset properly at the appropriate time.

My guess is that this is a variable scoping issue, partially because that was the issue the first time, and partially because Flash's scoping is about as confusing as watching Memento when you're tripping acid. As far as I can tell, variables instantiated within a frame are scoped globally, unless they're within a loop or function. However, commands, or anything else for that matter, only apply at that specific frame. This kinda makes sense. You might want to use a variable you defined somewhere else in the program, and you don't want all of your code executing at once. The issue here is, when are objects (like the scoreBox) that are defined in the scene, not in the code, created? Are they global? Can I change their values before they're visible? I'm still trying to figure it out, so if anyone has any suggestions, feel free to leave them in the comments.

As far as I can tell, it's only used for debugging, as my experiences with the actual Flash debugger were about as pleasant as shaving with a rusty butter knife.

Wednesday, July 9, 2008

Baby Steps

I think this is probably my first post ever that contains any actual coding in it, and frankly, I'm a little scared. This is such foreign territory for me, I don't know where to start.

So I'll start with a link. http://www.cs.drexel.edu/~asc38/Projects/Invaders/

Yes, it is in flash. I feel dirty with this being the first "complete" program I post, but we all have our flaws. I actually haven't paid for Flash CS3, but I'm using the 30-day free trial, and working fast. In terms of development, there are some things I like and some things I really dislike, but I'll get into that later.

If you can't tell by the URL, or the name, it's just a cheesy, quick Space Invaders clone. I programmed it in ActionScript 3, despite never having used it before, in about 3 hours. My main problem so far is that when there is contact between the lasers and their target. The lasers are (obviously) placed dynamically, and in their update method, I tried using the following line to "kill" invaders when they touch.

stage.removeChild(thislaser);
stage.removeChild(Invader1);

Which, on top of being horribly hardcoded, throws the following error.

Error #2025: The supplied DisplayObject must be a child of the caller.

I tried everything I could think of, and eventually just decided that it was just a "Flash Thing," until I realized that the lasers were being added like so:

this.addChild(newLaser);

The problem here was that when I was looking at how to dynamically add new objects, the tutorial didn't have their code in a function, it was just on the stage. Therefore, using the keyword this on the frame added for the stage, setting up for a similar removal with this.removeChild(). Apparently, when inside the function, this is not the stage. There was another issue, however.

The Invader still would not be removed via stage.RemoveChild. It continued to throw the "Child of the Caller" error. I intend to dig deeper into this, but not too much, though, since the issue is relatively moot. This is because the Invaders were added to the scene statically, which I found is unlikely to happen in any sort of "normal" game. Things that are dynamically added and removed (just as God intended,) come into and out of the scene without an issue. Not terribly enlightening, but at least it wasn't about the iPhone.

Monday, June 30, 2008

Get Ready To Grind Yourself Retarded

One of my current favorite web video series at the moment is The Escapist's Zero Punctuation. Ben Croshaw definitely has his own brand of humor, but I feel the need to comment on one of his common criticisms: grinding for inordinate amounts of time. First, a definition.

Grind (v): To repeatedly perform an identical action or sequence of actions in a game solely for the purposes of advancement otherwise unreachable.

Being forced by a game to perform the same action or actions over and over again is actually what gaming is usually about. Take any game you can think of. FPS, RTS, casual games especially, they're just an endless repetition of doing the same thing over and over and over, until you either fail to perform that action correctly a certain number of times, or you get bored/tired, and go to do something else. This isn't necessarily bad. Can you imagine a game where controls changed every two minutes, along with the perspective, goals, and game mechanics? It would be horrible and confusing. It could be intriguing to some (see: masochists,) but for most people, it would something that would be set aside almost instantly.

So, assuming that almost all games are a set of repeated actions, what makes some mechanics fun, while others are more boring and tedious than de-lousing your grandpa? Why is it that battling 500 rats or goblins to level up is mind-numbingly sloggy, whereas blasting your way through the Combine, Covenant, or NOD fun?

Pardon me for using programmer-speak if you're not into that, but the answer is shifting arguments. If you're the Ruby or Python interpreter, you don't mind seeing the same function called with the same values 500 times. You're a computer program, you don't even have feelings. In fact, why are you reading my blog? Get back to work, damnit.

Ahem.

As I was saying, people are not computers. We like things to change frequently, but in small and occasionally medium-sized ways. For example, most JRPGs I've played are basically big grinders wrapped in a tissue-thin container of plot. You encounter some bad guys, you have to hit "Attack" or "Magic," and direct death towards your enemies. Occasionally, there's a cool cut scene thrown in. This could be fun for a while, but eventually you know the key controls that you could be a blind vegetable (personally, I like carrots, but some people are partial to broccoli) and achieve the same results. The original Pokemon games (Red and Blue, for you youngsters) realized this, and also realized one of the potential ways to fix it. If you have so many different enemies that you only counter the same one every once in a while, it isn't that monotonous. Eventually, that will get boring, but before it does, they let you advance onto a new area with a new set of creatures to brutalize and enslave.

Causal games are the kings of grinding. In fact, it's pretty much their modus operandi. You take one concept, one mechanic, and apply it ad nauseum until the player is either comatose or victorious. Why are they still ridiculously fun (and addictive)? Variation. Bubble bobble and Sudoku wouldn't be fun if they had the exact same patterns every single time. Even before computer games were invented, we had crossword puzzles that had the exact same concept. Do a thing, change the parameters, do the thing again, etc.

So how does fun repetition become painful grinding?

  1. When you want to advance in the storyline, but can't because you have to grind some more. This is almost more of a pacing issue than it is a game mechanic issue. Of course, you don't want to just shuffle the player from cutscene to cutscene, with barely any gameplay (unless you're Devil May Cry 4, of course) but at the same time, you don't want the player to be so bored that they turn off the game before they get to the next plot point.
  2. When the challenges don't change at all. This should really be a no-brainer. It's why Postal workers used to go crazy. All work and no play makes Jack a dull boy. If you don't want your players to be bored, than switch things up a bit. Vary the enemies somehow. Difficulty, color, tactics, numbers, whatever, just try to throw a wrench in the player's grind machine every once in a while. They'll be surprised, possibly angry at first, but hey, angry beats bored.
  3. When the types of challenges don't change. This is subtly different from #2, but important. It's actually the reason why the concept of "boss battles" has done so well throughout the course of video game history. This is the "medium-sized" shift I was talking about earlier. The game mechanics can still be the same here, but there has to be a significant shift in what the player is doing with them. Instead of slicing through hordes of little enemies, they're fighting one very difficult one. Instead of building up a base and defenses, building an army and attacking, the player is given an army, and shoved out the door to complete an objective. Minor changes like the ones mentioned in #2 will hold off the feelings of grinding, but nothing abates them faster then having their usual plans rendered temporarily useless.
Whenever I design a game, or even a game mechanic, I always have to ask myself "would this still be fun after two hours?" I think that if more game designers did the same thing, then we wouldn't have to hear about how someone had to grind all night to get the items necessary to get up to level Y so they could make beef stew.

Wednesday, June 25, 2008

Why I Hate Flash

I could apologize for this being the first post in two months, but I won't. This is my third rewrite, mostly due to my incompetence, but frankly it's beginning to wear thinly on me.

I'm currently taking a game design course at my university along with two of my friends. Woo and yay. A class that actually may have some bearing on what I might actually do with my life. Don't get me wrong, but I don't see any time in my future when explaining if the character in John Updike's A&P will be required of me in the line of work. Anyways, I love gaming, I love game design, I love talking about game design, and I like several people in the class. However, after our first meeting, I feel a little down. Why? This sentence:

"2D Games will be done in Flash."

Well, there's the chandelier made of rabbit droppings. I despise Flash, and apparently most people cannot understand why, so I'm going to lay it out here, as much for me as it is for the half-dozen other people who will read it.

First and foremost, I don't like Flash because I have to pay to program it. This, if you didn't know, is a bit of an anomaly in the programming world. With the exception of Flash, there isn't a single other programming language that you have to pay to use. Even Microsoft's .NET languages have an open framework, and if you'll really itching to do some Mac-Based VBscript, you can use the (open-source, no less) Mono project headed by Miguel de Icaza.

As a student, the cheapest I could get flash for is around $250. If I wasn't a student, this price point goes up to $700. I have no problem with Macromedia Adobe wanting money for their code, that's all well and good. However, there is NO WAY to do anything in flash without using their IDE. Microsoft's Visual Studio is a great IDE. It comes with lots of awesome tools built in, and that's effing sweet. It also costs around the same amount as Flash. I couldn't find the exact price point, mostly because I was bombarded with offers for trial and free versions. There is a free edition of almost every Microsoft Developers product. They're called the "Express" editions, and though they lack the bells and whistles of the paid versions, they still get the job done. In fact, if you're a student, you CAN get free versions of the full product. Yes, that's right, you can get Microsoft products for FREE, if you're a student.

The reason for this is that Microsoft wants to get students used to using their products and their languages. It's a little sinister when you think about it, them baiting you with freebies when you're a poor college student, but Adobe doesn't even attempt to do the same thing, and basically just flips you the middle finger.

When I bring this point up, most people say "Why don't you just pirate it? Problem solved!" No, you vacuum-craniumed dolt, I'm a programmer. I want to get paid for the programs I write. If someone wants to charge for their program, that's fine by me. I love open source, but hey, someone's got to make a living somehow. If I don't want to pay for their development environment, then that should be their problem, not mine. My problem is that I cannot do Flash development without buying their product. Stealing it would be similar to a wheat farmer stealing potatoes. It's just wrong. Hell, I'm sure that half the reason Flash is so expensive is to offset the lost profits from people pirating it.

The other big pro-flash reason I get is this: artists use it. Well you know what, screw the artists. Last time I checked, a game artist should be doing artsy things, like drawing or modeling or whatnot. My job is programming, not theirs. If some beret-topped punter is going to tell me that he likes using Flash because he can program in it, that let me get my paintbrush out, cram it up my bum, and start "composing assets." Images are all the same. A JPEG in Flash is a JPEG to PyGame, or OpenGL, or DirectX. You want vector graphics? Awesome. Fireworks does SVG. I checked. If artists want to start doing programming, then I might as well go fly helicopters, because apparently I'm not needed anymore.

As vitriolic as I'm being, there would be one simple thing that Adobe could do that would make them a-ok in my book. Don't sell the platform, sell the IDE. If I can program Flash using a text editor, I'd go for it. Eventually, once I'd made some cash, I'd see the benefits to using the IDE, and purchase it. Having an up-front cost is nothing but an unnecessary barrier that is a relic of a bygone era.

Also, I'm hoping my artist friends take my slurs against them as being all in good fun. ;-P