a <- {
a="one"
b="two"
}
a.rawget("a") gives value one and if it is a.rawget("d") it gives error . i want to make a check if it d or any other that doesn't exist in the table . How to check?
Thanks in Advance
if (a.rawin("d")) print(a.rawget("d"));
How to make it a vice-versa?
should give a.
What do you mean?
I am making a translator i made some words english to spanish i want to make it reverse spanish to english, reverse without making another table. Is this possible?
a <- {
hola="hello"
puto="bitch"
yes="si"
//Question Words
what= "lo"
what_for ="para que"
when= "cuando"
where= "donde"
which= "que"
who= "quien"
whom= "quien"
whose= "cuyo"
why= "por que"
why_dont= "por que no te"
how= "Cómo"
}
if ( firstChar == "*" )
{
local splittext = text.slice( 1 );
local params = split( splittext, " " );
local my_array = ["hola", "puto", "what", "why", "what","what_for","when", "where", "which", "who", "whom", "whose", "why", "why_dont","how" ]
if ( params.len() == 1 ) Message(""+a.rawget(params[ 0 ]));
else
{
splittext = splittext.slice( splittext.find( " " ) + 1 );
local str = "";
for (local i = 0; i <= params.len() - 1; ++i){
if (my_array.find(""+params[ i ]) == null) {
a.rawin((params[ i ]));
a.rawset(params[ i ], params[ i ])
}
str = str + a.rawget(params[ i ])+ " ";
}
Message("[Translated] "+player.Name+" : "+str);
}
}
You would need to loop through all values in the table and their keys.
foreach( key, value in a )
{
if( value == text )
return key;
}
If you don't like to manage two tables then you could create one and use a for loop to replicate it and inverse the key and value.
Your original table:
a <- {
hola="hello"
puto="bitch"
yes="si"
//Question Words
what= "lo"
what_for ="para que"
when= "cuando"
where= "donde"
which= "que"
who= "quien"
whom= "quien"
whose= "cuyo"
why= "por que"
why_dont= "por que no te"
how= "Cómo"
};
Replicated immediately after except with reversed key->value:
b <- {};
foreach (key, val in a) b.rawset(val, key);
Result:
foreach (key, val in a) print("a: " + key + " -> " + val);
print("----");
foreach (key, val in b) print("b: " + key + " -> " + val);
Output:
[SCRIPT] a: yes -> si
[SCRIPT] a: what -> lo
[SCRIPT] a: what_for -> para que
[SCRIPT] a: how -> C├│mo
[SCRIPT] a: when -> cuando
[SCRIPT] a: hola -> hello
[SCRIPT] a: who -> quien
[SCRIPT] a: which -> que
[SCRIPT] a: whom -> quien
[SCRIPT] a: why_dont -> por que no te
[SCRIPT] a: why -> por que
[SCRIPT] a: where -> donde
[SCRIPT] a: whose -> cuyo
[SCRIPT] a: puto -> bitch
[SCRIPT] ----
[SCRIPT] b: bitch -> puto
[SCRIPT] b: si -> yes
[SCRIPT] b: quien -> whom
[SCRIPT] b: hello -> hola
[SCRIPT] b: cuyo -> whose
[SCRIPT] b: C├│mo -> how
[SCRIPT] b: donde -> where
[SCRIPT] b: que -> which
[SCRIPT] b: para que -> what_for
[SCRIPT] b: cuando -> when
[SCRIPT] b: lo -> what
[SCRIPT] b: por que no te -> why_dont
[SCRIPT] b: por que -> why
You manage one table and the other one is created based on your first one. If you want the fastest alternative. I hope you noticed that first elements are now last and you shouldn't care about that in the case of associative containers.