Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Scripting: obj.getstringkeys(str) (https://forums.graalonline.com/forums/showthread.php?t=74152)

Chompy 05-23-2007 04:27 PM

Scripting: obj.getstringkeys(str)
 
PHP Code:

function onCreated()
{
  array = {
"item1""item2"};
  for(
item : array.getstringkeys("item"))
    echo(
item);


Could be nice to do something like this :(

JkWhoSaysNi 05-23-2007 05:10 PM

if you need that functionality you can use my associative array: http://forums.graalonline.com/forums...ad.php?t=68643

Chompy 05-23-2007 05:15 PM

Quote:

Originally Posted by JkWhoSaysNi (Post 1311029)
if you need that functionality you can use my associative array: http://forums.graalonline.com/forums...ad.php?t=68643

huh?
Which function?

JkWhoSaysNi 05-23-2007 05:24 PM

It's a class for an associative array data structure. All it does really is map two arrays to each other.

{key1, key2}
{value1, value2}

all array.item(key1) does is find the index of key1 (in this case zero) and return the value at the same index (value1).

I provided functionality for looping through which is in the example usage.

Chompy 05-23-2007 05:34 PM

I don't see how this helps me :(

I want to do something like:

PHP Code:

function onCreated()
{
  array = {
"foo1""foo2""bar1""foo3""baz1"};
  for(
item : array.getstringkeys("foo"))
    echo(
item);


which would produce
HTML Code:

1
2
3

Instead of making a public function for it

If your class can do that, please give me an example? :D

DustyPorViva 05-23-2007 05:37 PM

.pos()?

Chompy 05-23-2007 05:40 PM

Quote:

Originally Posted by DustyPorViva (Post 1311044)
.pos()?

obj.pos would only get the first string, but obj.pos and obj.positions is for strings :O

DustyPorViva 05-23-2007 05:54 PM

Good point, though I guess you can do something like:
PHP Code:

function onCreated() {
  array = {
"foo1""foo2""bar1""foo3""baz1"};
  for(
item : array.size())
    if (array[
item].pos("foo")>-1) echo(item);


Hmm, as for the suggestion, I think it's good. Of course I think anything that benefits in someway and makes things easier is a good idea. Though many seem to think if it's possible to work around there's no need to make such an addition. Phooey.

JkWhoSaysNi 05-23-2007 06:02 PM

oh, i see. Nevermind, i thought you meant something else.

You could do something like:

PHP Code:

array = {"foo1""foo2""bar1""foo3""baz1"};

for (
0;i<=array.size()-1;i++) {
if (array[
i].starts("foo")) {
echo(
i);
}



xAndrewx 05-23-2007 07:42 PM

Use Dustys version!

HTML Code:

for (temp.currentArray: array)
{
  if (temp.currentArray.pos("foo") >= 0)
  {
    soforth
  }
}

Although, I wouldn't mind it being added too.

JkWhoSaysNi 05-23-2007 07:44 PM

Yeah, but then to echo 1,2,3 you have to create a counter anyway or then do array.index(temp.currentarray);

xAndrewx 05-23-2007 07:53 PM

Quote:

Originally Posted by JkWhoSaysNi (Post 1311079)
Yeah, but then to echo 1,2,3 you have to create a counter anyway or then do array.index(temp.currentarray);

no.

HTML Code:

for (temp.currentArray: array)
{
  if (temp.currentArray.pos("foo") >= 0)
  { 
    echo(temp.currentArray.substring(3));
  }
}


Chompy 05-23-2007 07:58 PM


You edited your post :)

PHP Code:

for (temp.currentArray: array)
{
  if (
temp.currentArray.pos("foo") >= 0)
  {  
    echo(
temp.currentArray.substring("foo".length()));
  }


But I would like this to be added :(

xAndrewx 05-23-2007 08:01 PM

Yeah :p
I forgot, I was trying to trim the selected text, not find the position!

I wouldn't mind it being added!

Chompy 05-23-2007 09:18 PM

Quote:

Originally Posted by xAndrewx (Post 1311087)
I wouldn't mind it being added!

Me neither :)

zokemon 05-24-2007 01:57 AM

But getstringkeys is for getting subvariables or variables that start with the parameter...it isn't meant for arrays at all!

Inverness 05-24-2007 02:39 AM

getStringKeys() hasn't been GS2ified, doesn't work with Object references.
PHP Code:

function getArrayKeys(array, key) {
  
temp.0// The array element
  
temp.out 0// The output array

  
for (e: array) {
    if (
e.starts(key)) {
      
out.add(e.substring(key.length()));
    }
  }
  return 
out;




All times are GMT +2. The time now is 04:54 PM.

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