[DGD]mappings, use of.
balduin at uni-paderborn.de
balduin at uni-paderborn.de
Wed Apr 14 10:58:27 CEST 1999
> Yeah Im afraid its me again. I need something cleared up.
> According to an LPC tutorial I have you can get the
> value of a mapping by doing the following:
> mapping test;
>
> test=(["smile":"$N $vsmile.", "grin":"$N $vgrin.");
Well this line contains a typo. It must read:
test=(["smile":"$N $vsmile.", "grin":"$N $vgrin."]);
^
where test is either declared as mapping or mixed.
>
> Now according to their examples I should be able to get
> "$N $vsmile." by doing the following:
> test["smile"];
> Or if I had a string called "command" for example and it
> contained "smile":
> string command;
>
> command = "smile";
> test[command] should return "$N $vsmile." as well...
> Instead I get the error message:
> Index on bad type
An Index on bad type error occurs in two cases:
a) You declare test as mixed and assign an array value by accident.
b) You declare test as either mixed or mapping and forget entirely
to assign a value to it. A newly declared mapping has the value
nil (or 0 depending on your dgd version), which is
different to ([]) (an empty mapping)
>
> There must be something really obvious to the rest of you as
> to what Im missing.
Perhaps you start with an easy example, where you create a new mapping,
and read it afterwards in the same function, just to get a feeling how a
mapping works. All what I can see is the typo in the first statement
you wrote, and this is probably a typo in this mail only.
> I blame my current bout of stupidity on a vicious bout of the flu :)
well catch a good nicht of sleep then and "Gute Besserung"
>
> |- mud at hal9000.net.au -|oOoOoOoOoOoOoOoOoOoOoOoOoOoOo...............
>
> List config page: http://list.imaginary.com/mailman/listinfo/dgd
>
good luck
Ludger
void map_test()
{
mapping test;
test = (["smile":"$N $vsmile.", "grin":"$N $vgrin."]);
write(test["smile"]+"\n");
}
works fine for me. (Outputs "$N $vsmile." to the current user)
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list