Author Topic: Building strings based on iterations.  (Read 1089 times)

I am not sure how informative the title is, so here's an example:


function chatmessageinfo(%playername,%msga, %msgb, %msgc... , %iterations)
{
    %target=findclientbyname(%playername);
    %entiremessage=%msga SPC %msgb SPC %msgc...;
    %displaymessage=put 1 %entiremessage here for each %iterations;
    %target.chatmessage(|\c1IterationInformer:\c6" SPC %entiremessage);
}
chatmessageinfo(Mr.Banana,Informative, ignore me being sloppy and not filtering out for not entered words, 5);
« Last Edit: December 22, 2014, 12:41:39 PM by Dannu »

for(%a = 0; %a < %iterations; %a++)
    %displaymessage = %displaymessage @ %entiremessage;

Thanks, that makes more sense than i thought it would have.

The list functions are useful functions that float around in many add-ons. I think they originated in the minigame events add-on.
Code: [Select]
function addItemToList(%string,%item)
{
if(hasItemOnList(%string,%item))
return %string;

if(%string $= "")
return %item;
else
return %string SPC %item;
}
function hasItemOnList(%string,%item)
{
for(%i=0;%i<getWordCount(%string);%i++)
{
if(getWord(%string,%i) $= %item)
return 1;
}
return 0;
}
function removeItemFromList(%string,%item)
{
if(!hasItemOnList(%string,%item))
return %string;

for(%i=0;%i<getWordCount(%string);%i++)
{
if(getWord(%string,%i) $= %item)
{
if(%i == 0)
return getWords(%string,1,getWordCount(%string));
else if(%i == getWordCount(%string)-1)
return getWords(%string,0,%i-1);
else
return getWords(%string,0,%i-1) SPC getWords(%string,%i+1,getWordCount(%string));
}
}
}

The list functions are useful functions that float around in many add-ons. I think they originated in the minigame events add-on.
But that's not what he wants to do
All he wants to do is concatenate all the arguments of a function together into one string, and then repeat that string multiple times
Using that, it will check through every single word every time he adds another one, which there's no reason to do for his case.
Also, because it checks if the word is already in the string, it wouldn't allow multiple of the same word, which he could have easily

Personally I don't like those functions. If I want to maintain a list of objects, I'll use a simset, which is managed by the faster engine code rather than script

Personally I don't like those functions. If I want to maintain a list of objects, I'll use a simset, which is managed by the faster engine code rather than script

Generally, what you should use depends on what you're storing.

1.Pre-existing objects (don't create objects just to store one value)-> use  ScriptGroup -> SimGroup -> SimSet, depending on what objects you're storing
2.Generic values (anything essentially - strings, numbers, special objects, etc)-> use  x[y] based array storage (value[n], length variables)
3.Immutable small list used for returning values without creating an object-> use  Separated string list

Generally the last option is a last resort and should never be encouraged.