Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-04-2008, 03:37 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
Add array range to new array

To get back in to scripting things other than GUIs and HP systems, I've decided to try and recreate PHP's explode() and implode() functions. I'm wondering, however, is there already an existing way to add an array range to a new array? Or will I have to script my own?

For instance, explode() has three parameters: delimiter, string, limit. If limit is set to a positive number that is less than the string's length when tokenized by the delimiter, it will add each token, with the last one containing the rest of the string. So, if my string is "1,2,3,4,5", my delimiter is ",", and my limit is 3, the output would be: {1, 2, "3,4,5"}.
__________________
"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-04-2008, 04:10 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
I don't believe there is already an explode() or implode() function.

I'd imagine you could do one like this:
PHP Code:
echo(explode(",""1, 2, 3, 4, 5, 6"3)); 
PHP Code:
function explode(delstrlimit) {
  
temp.token str.tokenize(del);
  for (
temp.0temp.token.size(); temp.++) {
    if (
limit) {
      
temp.output.add(token[i]);
    }else {
      
temp.positions str.positions(del);
      
temp.output.add(str.substring(positions[1] + 1));
      break;
    }
  }
  return 
output;

Good luck.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 12-04-2008, 04:37 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
PHP Code:
    }else {
      
temp.positions str.positions(del);
      
temp.output.add(str.substring(positions[1] + 1));
      break;
    }
  } 
That's exactly what I was looking for. Thank you, Tig. Though, for anybody thinking about using the script Tig provided: it's not the complete explode() function, as in PHP. I'll release mine publicly as soon as I finish it.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #4  
Old 12-04-2008, 07:14 PM
The_Kez The_Kez is offline
N-Pulse Asst. Manager
The_Kez's Avatar
Join Date: Dec 2007
Posts: 106
The_Kez is on a distinguished road
Send a message via MSN to The_Kez
What is explode be useful for? I've only ever done work in GS2 so this sort of stuff I've never heard of before.
Reply With Quote
  #5  
Old 12-04-2008, 08:24 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by The_Kez View Post
What is explode be useful for? I've only ever done work in GS2 so this sort of stuff I've never heard of before.
It converts a deliminated string to an array. Useful if you want to work with individual portions of a string without using messy string manipulation functions.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
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 07:01 PM.


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