Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-16-2011, 10:18 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Maybe also a temp.array.shuffle()? This would randomize the current array, allowing you to 'draw' each individual part in a sequential order.

This would be useful in, for example, a card deck script. You'd put all the cards in temp.cards, then use temp.cards.shuffle(); to randomize them (or temp.cardshuffle = temp.card.shuffle(); to store them in a new array.). You would then be able to grab the randomized variables and leave them in that order or clear the cards that you have drawn.



I ask this as last time I had to randomize an array, I needed to do something like this. I ended up having to take each variable in the array and throw them in random areas in a new array consisting of about a hundred null variables (so that they dont overlap.. too often) along with some other nonsense scripts, then I had to run through THAT, pick up the non-null variable, and then put them in a new array. Somewhere in there I needed to shift variables down a notch which took at least 15+ lines on it's own I'm sure.

tl:dr, it was an exhausting day.
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 08:23 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.