Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-16-2011, 09:03 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
array.random()

Wouldn't mind seeing something like this:

PHP Code:
function onCreated() {
  
temp.arr = {
    
12345
  
};
  
temp.element temp.arr.random();
  echo(
temp.element); // Echos 1, 2, 3, 4, or 5

Same thing as doing...

PHP Code:
function onCreated() {
  
temp.arr = {
    
12345
  
};
  
temp.element arr[int(random(0arr.size()))];
  echo(
temp.element);

__________________
Quote:
Reply With Quote
  #2  
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
  #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
  #4  
Old 03-18-2011, 04:07 AM
MattKan MattKan is offline
the KattMan
Join Date: Aug 2010
Location: United States
Posts: 1,325
MattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to beholdMattKan is a splendid one to behold
Send a message via AIM to MattKan
Quote:
Originally Posted by fowlplay4 View Post
Wouldn't mind seeing something like this:

PHP Code:
function onCreated() {
  
temp.arr = {
    
12345
  
};
  
temp.element temp.arr.random();
  echo(
temp.element); // Echos 1, 2, 3, 4, or 5

Same thing as doing...

PHP Code:
function onCreated() {
  
temp.arr = {
    
12345
  
};
  
temp.element arr[int(random(0arr.size()))];
  echo(
temp.element);

Yeah, that would be neat and useful
__________________
Quote:
Originally Posted by Satoru Iwata
On the other hand, free-to-play games, if unbalanced, could result in some consumers paying extremely large amounts of money, and we can certainly not expect to build a good relationship with our consumers in this fashion. In order to have a favorable long-term relationship, we would like to offer free-to-play games that are balanced and reasonable.
Quote:
Originally Posted by Unximad
Eurocenter Games remains attached to the values of indies game developer and to the service our playerbase community.
Reply With Quote
  #5  
Old 03-21-2011, 02:50 PM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
I thought random could never reach the limit so the last parameter would never be selected?
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!
Reply With Quote
  #6  
Old 03-21-2011, 03:38 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by MrOmega View Post
I thought random could never reach the limit so the last parameter would never be selected?
Arrays start at 0, so the last element is always Array.size() - 1. Which is why you can just pass the size to the maximum parameter in random.
__________________
Quote:
Reply With Quote
Reply


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 01:36 PM.


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