Thread: array.random()
View Single Post
  #3  
Old 03-16-2011, 10:54 PM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Better yet, let us write our own functions.
Quote:
Originally Posted by cbk1994 View Post
Adding methods to default objects would indeed be great. In JavaScript, you can edit object "prototypes":

PHP Code:
// from http://www.flzone.com/go?7678
String.prototype.replace = function(patternreplacement) {
  return 
this.split(pattern).join(replacement);

Another idea which I think would work better for GScript would be if you could create a class with the name "TServerPlayer" and all TServerPlayer objects would inherit those methods. This can already be done by joining classes to the player, but for stuff like TServerLevel and TGraalVar (for strings) it would be invaluable. I would love to be able to add string.replace(a, b).
PHP Code:
Array.prototype.random = function() {
  return 
this[int(random(0this.size()))];
}

// Or define it in class 'Array'
public function random() { ... } 
__________________
Reply With Quote