I had been toying around with the blockly concept, and while I haven't made the editor for it yet, I started to look at how it would generate the JS code, and an interesting pattern came up.
I wanted to continue to work on my Blockman project, and specifically wanted to code spell effects and enemy AI. But I want to achieve that by writing less code, while seeing the bigger picture. Every time I wrote enemy AI code, I'd simply get lost in waves of switch statements and call-backs so much so it'd make my head spin. This blockly conceot is awesome. Programmers might think it's shameful to use these drag and drop code editors since it's not programming in the true sense of the word, but I think this approach in the most sensible option for tweaking AI or status effect code. Really anything that has interaction or reaction.
Let's put it this way, this pseudo code is easy to say, hard to write:
Enemy "Bug"
"create":
this.state = "idle";
this.chargetime = new Timer;
"idle":
this.randomWalk;
if (player within 100)
this.state = "far attack";
this.chargetime.set(5); // 5 seconds
else if (player within 16)
this.state = "attack";
if (this.life <= 0)
this.setState("destroy");
"far attack":
this.chargetime.update();
if (this.chargetime.finished())
this.setFace("leap").leapTo("player").damage("player", this.atk * 2).resetFace().setState("idle");
else
this.moveTo("player");
"attack":
this.animate("attack").damage("player", this.atk).setState("idle");
"destroy":
this.createAnimation("die").kill();
But physically typing that out can be hard. Plus tweaking it can be a bitch. But in the background there are some obstacles I need to code in, for example:
this.setFace("leap").leapTo("player").damage("player", this.atk * 2).resetFace().setState("idle");
The above line of code is a giant queue, doing the actions from left to right in order. Therefore behind-the-scenes there needs to be an event manager per entity, and each entity needs to derive from an interface exposing this. So once I get that interface built, something like the above can totally work in a drag and drop code generator scheme.
Here's a spell:
Spell "fireball"
"create":
this.drain = 25;
this.power = player.intellect / 5 + 10;
"mouse-left-down":
if (player.hasMp(25))
this.drainMp("player", 25);
else
this.cancel();
"mouse-left-hold":
if (this.power < player.intellect * 10)
this.power += game.time * 100;
"mouse-left-release":
game.createProjectile("fireball", this.power, game.player.direction);
Projectile "fireball"
"create":
this.setState("move");
"move":
this.move(this.direction);
if (this.obstructed())
if (this.obstruction is Enemy)
this.animate("explode").obstruction.damage(this.power); // example may change
this.setState("destroy");
"destroy":
this.createAnimation("die").kill();
So, things like Spell, Projectile, and Enemy do much more behind the scenes. So, while I don't see drag and drop code creation useful for general code creation, I do see uses in AI "workflow" programming and spell effect "workflow" programming. Basically, anything with scripted events that need tweaking on the fly are better done in a visual fashion than by hand. Better yet is a direct game window to the left where you can immediately try out your changes, but that's for a different day.
I could do this instead of in my editor in a game. Then you can do game programming
in your game with the mouse. I attempted this once with a Pokemon game (Pokemon Azure) back in the day and had mild success with it.