Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #16  
Old 12-31-2008, 08:54 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
xD
Reply With Quote
  #17  
Old 12-31-2008, 10:05 PM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by Tigairius View Post
Right now your while loop will go in to an infinite loop if your input limit is greater than the array size of the source.
Oh, I see. Perhaps something like this?
PHP Code:
function randomstring2(sourcelimitrepeat) {
  if(
temp.limit == null) {
    
temp.limit temp.source.size();
  }
  if(
temp.limit temp.source.size()) {
    
temp.limit temp.source.size();
  }
  while(
temp.temp.limit) {
    
temp.trial temp.source[random(0temp.source.size())];
    if(
temp.repeat) {
      
temp.output @= temp.trial;
      
temp.i++;
    }
    else {
      if(
temp.output.pos(temp.trial) < 0) {
        
temp.output @= temp.trial;
        
temp.i++;
      }
    }
  }
  return 
temp.output;

Quote:
Originally Posted by DustyPorViva View Post
I agree that arrays are terrible for this sort of thing, simply because of the time it takes to set them up. I much prefer strings.
Well, I provided a source array that contains all possible single characters. So, it shouldn't take too much time to edit it, if you're simply looking to generate something from a list of single characters. Arrays offer the possibility of doing something like this:
PHP Code:
function onCreated() {
  
temp.source = {
    
"test",
    
"sources",
    
"foo bar",
    
"foo bar baz",
    
"foo!bar!baz"
  
};
  echo(
randomstring2(temp.source3true));
  echo(
randomstring2(temp.source3false));

Which outputs:
Quote:
foo!bar!bazfoo bar bazsources
sourcestestfoo bar baz
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
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:39 AM.


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