Tuesday, March 27, 2012

The pitfalls of JavaScript and a need for strict code reviews

Look at the difference between these 2 JavaScript function

Code A

function foo()
{
    name = "f";
}
Code B

function foo()
{
    var name = "f";
}


Code A attempts to access and set a global variable named "name" while Code B, because it include "var", creates a new, function scope variable called name and sets this.

It is a known pitfall that every JavaScript developer gets warned about but it is also a mistake that is very easy to make and very hard to catch, at least by hand.

This is one reason why, although a powerful web tool, JavaScript is a terribly dangerous language and I suggest you employ code reviews of the strictest kind. Sorry Douglas, although I enjoy your lectures and enthusiasm immensely and your book is very useful, JavaScript is seriously flawed, and this is just one example. By the way, for those interested in learning JavaScript, Douglass' lectures are a must see!

Here is how badly such 3 characters can effect a business

In Realm Of Empires, which runs inside Facebook's iFrame, we wanted to implement correct high sizing to eliminate scroll bars. To accomplish this, we had to use external Facebook JavaScript API FB.Canvas.setAutoResize.

For 3 years, developer after a developer have attempted to implement correct iFrame resizing for Realm Of Empires. For some reason, it did not work, no errors, no clues. In each case we abandoned this effort as we simply could not justify more time.

In the latest attempt just recently, I was determined to get it fixed and slowly started stripping down the pages to bare bones.I found that at some point the Facebook API started working. I narrowed it down to a couple of scripts that, when included, would break the code. I was still puzzled why those scripts prevented the code from working, and they were both not small or trivial.

Thankfully, a comment game me a clue needed! Someone said that renaming a global variable from name to username fixed their issue. I searched and found 2 instances where a global variable "name" was used instead of a function-scope one.

We would have found the issue sooner if we had dedicated more time, if we did a more thorough review of our JavaScript code, perhaps if we used some code review tools but the bottom line is that JavaScript does allow this mistake and you have to be on guard as this could have serious consequences

LESSON LEARNED
check and double check your JavaScript code! There are lots of automated code review tool that you will find helpful.


Thursday, February 16, 2012

Design Talk - eXperience Points


IN a NUTSHELL

XP

RoE Experience Indicator



 why and how

Today we’ll release a small but significant new feature – Global Experience Points (XP)

We often see players, in new realms, establishing their feeding priority by listing their Realm of Empires honors:

 “I have played ROE for 2 years now”
 “I was in Realm 7, 9, 11”
 “I am a Divine Emperor in another realm” etc

Well, XP will speak of your previous achievements; it will be your “Realm of Empires Experience Indicator

I want to take you for a design ride of this seemingly simply feature. I hope you will find it interesting!

Motivation for XP
We all know what XP is, but it took an hour long meeting to realize we just all knew it to be something different. What is it supposed to do? What is the purpose of having global XP. We agreed that our main motivation of XP is to be your “Realm of Empires game experience indicator”

Realm 4 
XP = Village Points?
We already have “village points” that speak of your experience. Titles are based on village points but titles are not game wide. Starting in a new realm, you are a “Peasant” like everyone else even if you have Divinity in your resume.

So perhaps XP should simply be your village points, totaled across all realms? Sounds good but that would result in huge XP (in millions), not ideal.

XP = Village Points / factor?
We could just scale the points down : 1000 village points = 1 XP, but there is also another problem - is a person who reached the level of Deity in just one realm equal in experience to a person who achieved a title of Emperor in 10 realms? Village point wise, yes they are equal, but Game-Experience wise? I could argue both ways.

Realm 5
Is 100 points = 10X10 points?
Also, is it harder to get your first 10 villages, than it is to get 110th village? On some realms, going from 100 to 200 villages is trivial – just take rebels, abandoned, inactive – until you are left with hard core of bad-asses and getting one more village is roughly analogous to having your 10th shot of tequila – you really want it, you’re not sure why, and it could result in losing it all - all the hard work flushed down the toilet; I may be speaking from experience.



Realm 7
So what is that tipping point? 100 villages? 200? 500? Well, it depends on the realm. The larger the realm, the more casual the realm,the easier it is to get more villages, so really, the XP should depend on the realm. But we don’t know this until the realm opens and runs for a while, so can’t do that well.

XP Only Village Points?
What about other things – is a player running a clan equal in experience to a person who has not? What about a player who organizes campaigns, helps new players via forum, chat, achieves top spot in tournament realm etc? Certainly these are things worthy of a bit of XP. Because of this, we give out a lot of XP per title to give us room to give out less XP for other actions in the game (and also a reason why we cannot simply scale 1000 village points to 1XP).

XP Levels
But giving a lot of XP results in a very big number that is inconvenient to display therefore we decided to introduce XP Levels – a collapsed version of your XP.

Final Decisions

Oh btw, I am an AD&D fan. [Established feeding order now] Been a dungeon master for many years, have a lot of great campaigns behind my belt, killed off many great characters, managed to put a friend to sleep once while he was talking – that was before twitter but now I would SOOO tweet about this!  Anyway! The point is, XP design was loosely inspired by D&D. 

XP loosely based on village points, with diminishing return 
For now, you get XP for accepting titles which is based on points but not linearly - there is a diminishing return as you advance in titles. We did this for many reasons, one being that we did not want to make it practically impossible for a determined new player to catch up to veterans.

More realm = more XP
We went with the assumption that a person getting fewer total villages in many realms, is more experienced than a player with more villages in one realm – reason: the former player has seen more types of game play, has seen more diplomatic situations, has probably participated in many more clans, dealt with more player etc

XP Levels - a linear function of XP
Unlike D&D, XP levels are a linear function of your XP.
Want to know what it is?
Get ready for it!
It is Level = XP / 1000 wooho! My mathematics degree finally paid off!

XP already nonlinear function of village points
Since XP is already a nonlinear function of village points, we figured it makes no sense to have XP level to be an nonlinear function of XP – its like double taxation; not sure exactly what it is, but we all know it’s really bad.

XP Realm specific so adaptable
At the end, XP is tied to a title and it is realm specific. Meaning we can tweek the algorithm by adjusting the XP per title in future realms based on your feedback. You will able to see this flexibility in action in tournament realms where we’ll give out fewer XP.

We look forward to your feedback!
We have not had a chance to get much on your feedback on this, partly because we screwed up… we did not foresee so many questions popup up and we must release this code before RX2 reopens tomorrow. However, because the algorithm is adaptable, we hope that once you guys get a chance to experience the experience points (pun intended), your feedback will be that much more valuable.

Thanks goes to my daughter for waking me up at 5:15 am and giving me a chance to write this.

Q & A - based on player's questions 

Q: How were the starting points calculated, today?
The points were calculated based on your title in all your current realms as of today

Q: Will I loose XP points/level if I stop playing a realm?
No, like titles your XP points, will never go down. Unlike titles, your XP will not go down even if you stop playing on a realm

Monday, January 23, 2012

Future of online gaming - sad world of gambling

Disclaimer - I wrote this post a while ago but never published it however with the recently announcement that Zynga is entering the real-world-gambling, I thought it was fitting. 

Why is Online Poker effectively outlawed in the USA?


Poker is an addictive (and fun!) game where a player is able to loose a lot of money very quickly. Online Casinos have caps on the amount of credits you can buy daily but that does not work. First of all, a $750 daily limit (typical amount in my experience) is a no limit at all - it might as well be a billion dollars - for the vast majority of people, its not reachable. Secondly, one may play on many websites cranking that limit to $7,500/day or more.

So, (1) you can loose a lot of money in poker, (2) and its addictive, (3) and we need to protect people from themselves, (for their good, or common good) therefore (=>) no online-poker. That's the reasoning regardless if you agree with it or not. This extends to all kinds of gambling, addictive substances etc.

So what does this have to do with the future of online gaming Greg?!?
Well I am glad you asked! Video gaming is a huge industry. Do-it-quick Video Game collage programs are pooping up everywhere, Triple-A title sales are beating Hollywood records.

But Facebook, MobWars and recently Zynga proved that online gaming is the way to go. MobWars proved that people will spend millions of dollars JUST to have a higher score than their friends. Everyone wants to be on the bandwagon.
Online-games are not games, they are virtual slot machines. Parents beware!
Online-games, at least the vast majority of the recent titles, especially on facebook, are not "video games made available online". They are online slot machines that addict players, then allow them to spend lots of money to continue getting their fix.

Employing slot machine-like sounds, silly rewards like score or levels (compared to your friends), they entice players to spend more money to allow them to perform more, usually totally mindless clicks that offer more silly rewards.

Don't believe me? Look at many of the Zynga games, turn on the sounds, perhaps close your eyes for a moment and ask yourself where you are? Las Vegas perhaps?

Saturday, January 21, 2012

Free-to-play damaging game industry?

Yes.... at least according to this Inside Mobile Apps article:
Gamespot is reporting that Olivier Comte, Namco Bandai’s SVP for Europe has come out swinging against the free-to-play model, saying games that follow the model aren’t high quality, and that low-cost games lower the perceived value of games, ultimately harming publishers. 
I am not sure I agree with this completely, however, I would agree with a stronger statement : pay-to-advance games are the real problem (like most of the games on Facebook now are)



There are fun games coming out on Facebook but most do not offer a price-to-buy-full-version or even a subscription model. I tried Hidden Chronicles recently, and although I could see it as a game I could play with my kids, I know, or suspect, I will need to spend enormous amounts of money (or spam friends) in order to continue playing as long as I would like to. THANKS, NOT FOR ME! 


If I could BUY the "full" game, or even pay a monthly subscriptions to to use the game, I would continue playing. 


I guess developers prefer to have a few players spending a lot of money, than offer other options allowing more players to play for less.


Lucrative business model? It is a relatively new model and it certainly worked well for some developers recently but maybe there are signs that players are smartening up?


I certainly hope this will change because I do want to play SimCity online, I do want to a strategy game without having to spend hundreds of dollars like at Kingdom of Camelot or other games Kabam is now pumping out. 


This is why we, at Realm Of Empires continue to offer a subscription model - play indefinitely, enjoying the full game for less then a price of coffee at Starbucks per month. 


Unfortunately Realm Of Empires is now the last game of its kind that offers a subscription, no-benefit-to-paying-players model, at least that I know of.