[ tamius.net | &DnD — Quick guide to magic++ ]
« back to the first page

General rules

I don’t think I have to run through the general stuff about magic++. If you know C or Java or C#, you should already be most of the way there, though please note that much like with Bash or Javascript, the magic++ script (spell) doesn’t have to be inside a class or function to execute. Other than that, it’s nothing special.

For people new to programming, here’s some quick rules:

1. Each command should end with a semicolon.

2. if/else/else if work exactly the way you think.

if (condition){
  //do stuff if first condition is true
else if ( other condition){
  //do stuff if first condition is false but the second condition is true
  //do stuff if both conditions are false

The part where you don’t need to use brackets if there’s only one command in the if block applies as well. The ternary operator (condition ? true : false) works as well.

3. Theoretically, while, do-while, and for loops can be used as well, but are discouraged.

4. Variables are generally not strongly typed, (but they may be). Type ’Object’ can be used for anything and everything. Interpreter should guess the context automatically. You can always force a specific type if you want, though.

But what exactly is a variable? In simpler terms, a variable is like inventory slot. It can hold exactly 1 stuff. You can make it out of thin air (within reason. DM can give you out of memory exception, which effectively shuts down your spell). When you make it, you must put ’Object’ in front of it, like so:

Object x;

Congrats, you now have a variable where you can store data and stuff for magic++. You do that for everything you do. There’s a single exception (see: casting a spell), but more about that later.

You can also make an array of objects:

Object x[];
Object y[5];

In example above, x has no elements. y has 5 elements, but all of them are empty. This is important when trying to determine length of the array: x.length will return 0 while y.length will return 5. Arrays are zero-based, so the first element in the array would be y[0] and the fifth would be y[4].

5. Comparing and assigning.

Object x;
x = 5;     // this is a command that makes ’x’ have a value of ’5’
x == 5;    // this is a command that returns ’true’ if ’x’ is equal to ’5’, false otherwise

So, if there’s one equal sign, you’re making left side of the command be just like the right side. Two equal signs mean you’re comparing them. Other comparators:

!=      not equal
<       less than
>       more than
>=      more or equal
<=      less or equal

Comparators are generally used as conditions in if statements and loops. Some types of objects might contain methods which also serve as comparators.

6. Operators:

+, -, *, /, % — you know what they do. They work with numbers.
&&, ||, ^^, ! — and, or, xor, negation. They work with stuff that’s either true or false. (’false’ is equivalent to 0, ’true’ is same as every other number).

No bitwise operators.

7. You can also define and use functions:

function name(arguments){
  // do stuff
  return [a value]; //optional

That was a quick crash course. Moving on.

Speed of execution (of spells)

By default, it’s 1 instruction per second. If a single turn takes 6 seconds, this means a spellcaster’s spell will only advance by 6 instructions in that turn. If the player has moved in that turn, their spell may only advance by 3 instructions (but DM can and may change those values at any time). In general, one semicolon means one instruction (exception: function calls). So, this is an instruction:

Object x = 3;

This is also an instruction:

Object x = 3+5;

And this too is a single instruction, albeit a long one:

Object direction = Player.getPointingDirection(Player.RIGHT_HAND);

And this is two instructions:

Object x;
x = 3;

So mind your spells. There’s a few special cases for counting instructions, though.

If statements

Counting how many instructions an if statement takes can be a bit tricky. In general, evaluating a condition is considered a single operation, regardless of how many comparisons it includes (unless condition contains multiple function calls. DM may also put a limit on how many comparisons you can use with each if statement). For example, given this spell:

Object x = true;
if( x ) {
  x = false;

if( x ) counts as instruction and gets executed regardless of whether ’x’ is true or not. Since ’x’ is true, the above snippet is three instructions. If ’x’ were false, the above code would be considered two instructions long (x = false wouldn't execute).

This ’if’ statement also counts as only one instruction:

if (x == 3 && y != 2)

In a longer if/else if/else block, instructions are counted like so:

if( x == 2 ) {           //+1 instruction, counted always
  // code
else if( x == 3 ) {      //+1 instruction if x is not equal to 2, +0 otherwise
  // code
else if( x == 4 ) {      //+1 instruction if x is not equal to 2 or 3 +0 otherwise
  // code

else{                    // Doesn’t count as an instruction.
  // code


If you know how to use the ? operator properly, you deserve some extra leniency. This counts as single instruction:

Object a = x == 3 ? 6 : 9;

Note that the DM may put limits on how many nested ? operators you’re allowed to have in a single instruction, or restrict the ? operator altogether.


Aren’t a way to magically shorten the execution time of your spell. DM is supposed to simulate execution of the loop, six instructions per turn. The control part of the loop (e.g. while(a < 3)) counts as n + 1 instructions, n being the number of times the loop gets executed.

For example, the following code is worth 8 instructions:

Object a = 0; // +1 instruction

while(a < 3){ // +4 instructins
  a++; // +3 instructions, since loop gets executed three times

Do-while loops are a bit different:

Object a = 3; // +1 instruction
do {
a++; // +1 instruction
} while ( a == 0); // +1 instruction, but the loop doesn’t repeat as a != 0

For loops are a bit more complex to count. Suppose we have the following loop:

for (Object i = 0; i < 3; i++){

Above loop is worth 11 instructions: Object i = 0 is executed at the beginning of the loop, i < 3 gets executed as many times as while(i<3) would (in that example, 3 + 1 times). i++ gets executed after all instructions in a single loop turn have executed (in that particular example, 3 times). a++ gets executed three times as well, 1 + 4 + 3 + 3 = 11.


The amount of instruction cycles a player-generated function needs to fully execute is equal to the number of instructions within it. DM should simulate player-generated functions. Functions provided by magic++ count as one instruction (unless otherwise specified in this manual).

Each function call counts as an instruction.

Limits on spell use

Some spells may be limited in how frequently you’re allowed to use them. DM doesn’t have to tell players how many uses of a spell they have left in the specified period of time. DM should keep count of how often players use their spells, so the spells aren’t permitted to finish successfully.

If a player starts casting a spell they’ve used too many times in the time period, the spell only fails when the player finish executing it.

Interruptions while executing spells

Player can voluntarily cancel their spell at any time. If player’s spell consisted of calling multiple spells or effects, already completed spells count towards the spell limit (if specifies) and their effects persist despite the cancellation. Same applies if the player executing a spell is interrupted by an attack.

If the spell is interrupted (either voluntarily or not), it cannot be resumed as all Objects associated with it are gone. Instead, the player casting the spell must start at the beginning.

If the spell that was interrupted made any changes to the world, then the player may modify their spell to detect and use these changes.

Things that interrupt spell execution are:

  • player performing an action (other than executing the spell)
  • running (walking is fine, but reduces spell executing speed by 50%)
  • player taking damage
  • player attempting to avoid taking damage (by means other than casting their spell)

In addition to that, a DM can decide whether any other event or action is able to interrupt save. Player may make a saving throw to avoid interruption by the causes listed above.