🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Still working

Published March 07, 2006
Advertisement
Still working on the Shi Sen daily puzzle. Toughest part to do is the search to check for valid moves. Thankfully, I already wrote that in C++ a buncha years ago for my C++ version.

C++ to ActionScript conversion is both easy and hard. And, interestingly, it's exactly the opposite of what I'd expect. In the past when I had to convert C++ to something else (like Pascal or some high-level database language), the bugaboos popped up with the nasty little bit-fiddling operations that C++ handles beautifully but higher-level languages consider to be the realm of nerdy assembly-monks cloistered in towers on the Microsoft campus. So converting something like this. . .

X = (Y & 0x000f) << (B ? 1 : 2);

(which means "Mask off all but the last four bits of Y, then shift it either one or two bits depending on whether B is true, then store the whole mess in X")


. . .into something that just didn't handle bits or non-decimal bases was just nasty and often required the whole thing to be stretched out over several lines, maybe with a few temp variables thrown in.

Thankfully, ActionScript (i.e. ECMAScript) was hoped to be a scripting language with which engineers could hack together solutions easily, so it handles the above bit-fiddling just fine.

The problem comes with the "big picture" stuff like variable scoping. ECMAScript variables (unlike C++ variables) are static by default. Nonstatic variables must be declared by the nonintuitive "var" declaration.

myFunc = function(x)
{
y = x;
var otherY = x;
}

// now call it
myFunc(3);

// and see what we have
trace(y);
trace(otherY);

The output will be:

3
undefined

Unlike C++, y is now the caller's namespace rather than disappearing when the function goes out of scope. If you want your variable to go out of scope, you must "var" it.

It's just something to watch for. Especially when you're making a recursive function, like my Shi Sen search. You WANT your variables to stack themselves and dutifully go out of scope when the function completes, so plan to watch your scope when converting.

That is all for now.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement