Author Topic: Listing Arrays  (Read 2246 times)

So there are two variables I want to list the arrays of. $Support_Maps::MapName, and $Support_Maps::MapAuthor.
The arrays are just strings, like $Support_Maps::MapAuthor["Zapk"].
--------------
Is there any way I can use a loop to list all of the arrays from a variable?

export("$Support_Maps::Map*");

export("$Support_Maps::Map*");
Yeah, I want to be able to messageClient each array though...
$Support_Maps::MapAuthor[ <MessageClient This String> ]

Yeah, I want to be able to messageClient each array though...
$Support_Maps::MapAuthor[ <MessageClient This String> ]
export("$Support_Maps::Map*","config/server/temp.txt"); then use a fileobject and parse file

Or store all the string in another array when you create them

Are you talking about trying to do something like this?

$say[0] = "This";
$say[1] = "is";
$say[2] = "how";
$say[3] = "it";
$say[4] = "works.";

for(%i=0;%i<=5;%i++)
   echo("Elm: " @ $say[%i]);

I made a system that works good, but I'm getting errors while trying to execute it ingame

Quote
function Support_Maps_PrintList(%client)
{
   for(%a = 0; %a < getWordCount($Support_Maps::RawList); %a++)
   {
      %Name = getWord($Support_Maps::RawList, %a)
      messageClient(##%##client, '', "\c6 - \c4" @ %Name);
   }
}

Are you talking about trying to do something like this?

$say[0] = "This";
$say[1] = "is";
$say[2] = "how";
$say[3] = "it";
$say[4] = "works.";

for(%i=0;%i<=5;%i++)
   echo("Elm: " @ $say[%i]);

No. Read the op.

you forgot the semicolon at the end of the getWord call


I made a system that works good, but I'm getting errors while trying to execute it ingame
No. Read the op.
What you said in the OP has nothing to do with the code you put in that post


If the names of the variables are themselves the data, you probably need to rethink your data structures.
There's no nice built-in hashmap class, so IMO you should use elm's example.

If the names of the variables are themselves the data, you probably need to rethink your data structures.
There's no nice built-in hashmap class, so IMO you should use elm's example.
Yeah but they can be anything like
$this["Forest"]
$this["Magic Bob's Playland"]

If the names of the variables are themselves the data, you probably need to rethink your data structures.

Did you even read that subpixel?

Yeah but they can be anything like
$this["Forest"]
$this["Magic Bob's Playland"]

Arrays have to start with zero you would have to do something like

$this[0] = "Forest";
$this[1] = "Magic Bob's Playland";

I'm not to familiar with arrays so I may be wrong

Subpixel has a valid question. To help you guys better understand what he is asking, maybe this example will help:

Code: [Select]
function serverCmdSetWordReplacement(%client,%original,%replacement)
{
%client.wordReplacement[%original] = %replacement;
}

package WordReplacement
{
function serverCmdMessageSent(%client,%message);
{
%message = replaceWords(%client,%message);
Parent::serverCmdMessageSent(%client,%message);
}
};
activatePackage(WordReplacement);

function replaceWords(%client,%message)
{

}

What would you put in the replaceWords function?







As a solution, I've seen most scripts add a line to where they set pairs:

Code: [Select]
function serverCmdSetWordReplacement(%client,%original,%replacement)
{
%client.wordReplacement[%original] = %replacement;
%client.wordReplacementInputs = trim(%client.wordReplacementInputs SPC %original);
}

package WordReplacement
{
function serverCmdMessageSent(%client,%message);
{
%message = replaceWords(%client,%message);
Parent::serverCmdMessageSent(%client,%message);
}
};
activatePackage(WordReplacement);

function replaceWords(%client,%message)
{
%inputs = %client.wordReplacementInputs;
%count  = getWords(%inputs);

for(%i = 0; %i < %count; %i++)
{
%input       = getWord(%inputs,%i);
%replacement = %client.wordReplacement[%input];
%message     = trim(strReplace(" " @ %message @ " "," " @ %input @ " "," " @ %replacement @ " "));
}

return %message;
}

This would also give you functionality to check if a field has been set:

Code: [Select]
if(strPos(" " @ %client.wordReplacementInputs @ " "," " @ %fieldToCheck @ " ") != -1)
And remove a field when you perhaps clear the key -> value pair:

Code: [Select]
%client.wordReplacementInputs = trim(strReplace(" " @ %client.wordReplacementInputs @ " "," " @ %fieldToRemove @ " ",""));