Help

JPG-STRING-CONCATENATION

It is very important you minimize the number of times you use the "+" concatenation operator to create strings. It is okay to use it when you really need to, but you can almost always dramatically reduce the number of times you use it using various techniques.

GOOD Use CARET-SUBSTITUTION instead of String concatenation

For example,

inRoom.msg( "^n looks at ^2n.", self, actor );

is MUCH faster than:

inRoom.msg( self + " looks at " + actor + "." );

GOOD Use the String format method f() instead of String concatenation

Also, using the JavaScript String format method f() is much faster than string concatenation in most cases. For example:

'HP:%d/%d'.f( actor.hit, actor.maxHit )

is much better than:

'HP:' + actor.hit + '/' + actor.maxHit

GOOD Build strings in advance and then reuse them.

If you do need to use the + concatenation operator try to do in advance and cache the value if possible. See JPG-CACHE.

GOOD  Use multiple arguments instead of + concatenation operator
      when possible.

Many functions, like act() allow multiple arguments to be passed to them. For example,

act( 'wave', actor );

is equivalent to (but is much faster than):

act( 'wave ' + actor );

Try to think of the string concatenation + operator as a really rich dessert. If the mud eats too much of it it'll become unhealthy. It is okay to use it in moderation.

If you find a situation where you think you need to use it heavily please see the administrators. Possibly we can add a new built-in function to make accomplishing what you're trying to easier.

Note that using the + operator to add numbers, like "5 + 3" is perfectly fine and is not a problem at all. It is only using + to add strings which is problematic.

Last edited by Winterstar in May 2004.