Using C# Reflection for simple variable saving

Unity uses a simple key/value system for saving variables that is called PlayerPrefs. My biggest beef with this system was always thinking up a unique key string for each variable that I was saving. I looked up a few articles online and came up with this system using Linq Expressions.

using System.Linq.Expressions;
using System.Reflection;
public static void SaveVar<T>(Expression<Func<T>> _var)
{

var body = ((MemberExpression)_var.Body);
string var_name = body.Member.Name;
var var_value = ((FieldInfo)body.Member).GetValue(((ConstantExpression)body.Expression).Value);

}

Use like this – SaveVar(() => EnergyCurrent);

This doesn’t go into the specifics of using PlayerPrefs to save a variable, but the important part is that it gets the variable name and value. From there, it’s simple to send it to whatever to save it.

Dishonored

Today, I finished Dishonored, developed by Arkane Studio and published by Bethesda. It is so good, I’m actually going to replay it. This is a monumental occasion, because I do not, I repeat, do not replay single player games. The only other single player game I can remember replaying is Persona 4, and that just happens to be my favorite game ever. So there. That’s probably one of the highest compliments I can give to a single player game.

As a foreword, there will be spoilers in this article.

Dishonored is, first and foremost, a stealth game. While combat is fluid and quite fun, the game lets you know from the beginning that you should not be charging into the fray. From a first-person perspective, Dishonored manages to get around the common annoyance of not being able to observe enemies by giving you an almost too-large view from leaning around corners. As long as the main character, Corvo, has his body behind something, his head can be poking full out at just about everything, except those magical all-seeing Tallboys.

Stealth games have a certain intensity, that is, I don’t want to get caught by the enemies. Therefore, I want to keep moving as much as possible without being seen.

There’s one major problem though – The world of Dishonored is really, really awesome.

So I’m sneaking around, and then I just have to stop and see the sights. Now, I’m not saying this is anything but minor, but I just wish there was a mode where I could do anything without fear of being seen.

While you have several dialog options within the game, Corvo never speaks. While, as usual, this leads to a few awkward situations such as not saying anything while being framed for murder, the developer’s main reason for doing this was to allow the player to project themselves onto the character.

And it worked.

I didn’t even realize it was happening to me. But throughout my first playthrough, my Corvo was sad. Sad at what had been taken from him, at the state of his country. I didn’t kill those I had another option to, because they were only doing what they’re told.

My new Corvo is different. My new Corvo is angry.

Angry at those who would try to ruin him, those who would kill his beloved Empress. He will destroy all of those in his path.

Because Corvo never speaks, he can’t refute the personality I have attributed to him. This makes for an experience, where while personal choices have very little in the overall way of gameplay, I feel connected to the character and the world.

And what a world it is! Plague and tyranny have beset the land. Dishonored wins for never making the player feel stupid in the decisions it presents. Dishonored is a world of gray. Who is deserving of death? The member of a local guard, only doing what he is told? The leader of a hypocritical religious order? A tyrant, who “only wanted to make the world better”.

These decisions are not presented in black and white, and do not affect the world in black and white. While, truthfully, there is a “chaos meter” which affects the ending you get, knowing that shouldn’t affect the way you play at all.

Dishonored is one of this year’s best titles, and it came out to an industry that was determined that single player, new ideas, were determined to fail.

Forgot to save!

So I’ve decided to start playing Baldur’s Gate 2. I’ve heard it’s fantastic (yes.. haven’t played it, sue me). I’ve had a hankering for a good RPG lately, and honestly, I haven’t been able to find a good recent one.

First I tried replaying Dragon Age: Origins. I enjoyed DAO a ton, but reducing your game’s choices to several big choices can limit the replayability of the story. In the gameplay department, it just seems to be missing some necessary RPG conventions that could give it that extra “oopmh”. While it has a decent subclassing system, I feel it could be a bit more expansive. Let me think of some really, really creative builds, if I so choose to.

I also tried Skyrim – but ever since Morrowind, there hasn’t been nearly the number of factions that really allow me to come and create my own character.

In general lately, games have failed to allow me to create my own character – Some minor customizations don’t count. I want to at the very least feel like I have my own character or playing style. I think the last game I played that really did this was Dark Souls.

A friend tried to convince me that Skyrim had a lot of different ways to play, but I’m not seeing it. I can swing my weapons at them, or shoot them with stuff. The combat spells had very few differences between them, and weapons – while feeling different – don’t have a lot of really cool differences in how your character is created.

So, Baldur’s Gate 2 it is. Unfortunately, I played through most of the beginning area and forgot to save – so I’m taking a break.

I’m never going to play a good rpg -_-.

The Secret World’s disappointing Egypt

I beat the first “act” of The Secret World. Now I’m in Egypt.

And it’s pretty damn boring.

When I started TSW, I was in an area that I felt was very unique for an MMO. It was a small town, with people that didn’t really know what they were dealing with. It was refreshing, the quests were interesting, and I was enjoying myself immensely.

Move to Egypt, and I’m helping out a group of military people fight cultists. My townspeople that were homey and just trying to make it through the day were replaced with a boring group of standard militia, and my exciting and creatively used enemies are replaced with CULTISTS.

You know how many times I’ve fought cultists?

So I’ve stopped playing for the moment. My friend Armen pointed out an amazing parallel – In Age of Conan, he started in the main town, had a ton of fun, and then quit when he reached the main area because he was fighting cultists.

That makes two Funcom games with promising ideas that fail to deliver.

King Arthur’s Gold

Recently I’ve been playing http://kag2d.com/en/. It’s in early alpha, but has an interesting and unique idea.

Two opposing teams start out on both sides of the map and are given a limited amount of time to create structures without fear of the opposing army interfering. From then on, the back goes wild, medieval style! Knights charge, archers arch, and builders tend to place things in really awkward places. Sometimes, at least.

King Arthur’s Gold plays really well because of something I’m deciding to call Convergent Strategy (It probably has a real name). Basically, without directly communicating, a team naturally understands what they have to do with their teammates to win. For example, if I start the edge of a tower in KAG, players will come and start filling in the blanks to my tower without any instruction from me.

Multiplayer games in general these days tend to forget the basic fact that you can’t just allow for teamwork, you have to make it natural. Pub games don’t have players directly communicating (and if they are, it usually isn’t pretty), so players have to naturally understand the teamwork that they need to do.

Some of the tricks here involve having simple objectives, with potential for depth and strategy. In KAG, the goal is to take the enemy’s flag. Because of the player’s ability to build structures, it is naturally understand that building structures that prevent the enemy from just waltzing into your base are good. And since there is a limited amount of playing space, it just makes sense to build in the same areas as your teammate. See https://www.youtube.com/watch?v=rh52OahYxIw&feature=player_embedded.

So I’ll probably continue playing King Arthur’s Gold for a while. On a personal note, it’s good to finally have a multiplayer game that really pulls my interest, since it’s been a while.

Clan AN.US assemble.