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
  #1  
Old 12-31-2008, 03:35 AM
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
No upside to using a string, I just didn't feel like doing temp.source = {"A", "B", "C", etc};
I think it's generally bad practice to use a while() loop where a for() loop can be used, and right now it doesn't look like you have any loop protection, so if you input incorrect parameters you can break the loop limit.
I did use a for() loop, originally. However, that results in temp.i increasing, even though nothing is added to temp.output. That results in outputs that aren't the length defined by temp.limit.

Also, I have no clue what "loop protection" is. A search leads only to this topic.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #2  
Old 12-31-2008, 04:46 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by LoneAngelIbesu View Post
Also, I have no clue what "loop protection" is. A search leads only to this topic.
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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 12-31-2008, 04:56 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
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.
If repeat is true then it will do that. Easy fix would be to return when output size equals source size
__________________
Reply With Quote
  #4  
Old 12-31-2008, 06:28 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Chompy View Post
If repeat is true
Yes, that's what I meant
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #5  
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 03:51 PM.


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