How about adding .name to the struct returned by Realms()?
How else would you get the realm name if you have to loop through all the realms, looking for something? (Well besides from a escript function, with a case on mapid, but that is not a nice solution)
.name on Realms()
Moderator: POL Developer
Just .. give this a try (trust me)
Remember that Realms() returns a dictionary.
The key is the realm name. You could also use ( Realms.Keys() ) to only get the realm names. If you iterate Realms() directly though, the pointer becomes the key name. In an array it would be an integer. _(var)_iter is a bonus variable in foreach loops (since 095)
Code: Select all
use uo;
use polsys;
Program ShowMeTheRealms()
foreach realm in ( Realms() )
Print("I am on realm ->"+_realm_iter);
SleepMS(2);
endforeach
return 1;
endprogram
The key is the realm name. You could also use ( Realms.Keys() ) to only get the realm names. If you iterate Realms() directly though, the pointer becomes the key name. In an array it would be an integer. _(var)_iter is a bonus variable in foreach loops (since 095)
I have been running a shard since pol92 singlehanded, worked with Dict, struct in EScript. I have worked with iterators in C++, yet I would have never found out that myself, and I dont remember seeing any documentation or core changes for that.
Maybe add a few words about this in the documentations for Dictionary, in http://poldoc.fem.tu-ilmenau.de/pol096/ ... Dictionary.
Thanks for your help
Maybe add a few words about this in the documentations for Dictionary, in http://poldoc.fem.tu-ilmenau.de/pol096/ ... Dictionary.
Thanks for your help
Better elaborations...
The variables:
var alpha := dictionary{"a"->1, "b"->2, "c"->3};
var bravo := array{"a", "b", "c"};
The variables:
var alpha := dictionary{"a"->1, "b"->2, "c"->3};
var bravo := array{"a", "b", "c"};
Code: Select all
foreach key in ( alpha.Keys() )
Print(_key_iter+"=="+key);
endforeach
Result:
1==a
2==b
3==c
Code: Select all
foreach value in ( alpha )
Print(_value_iter+"=="+value);
endforeach
Result:
a==1
b==2
c==3
Code: Select all
foreach value in ( bravo )
Print(_value_iter+"=="+value);
endforeach
Result:
1==a
2==b
3==c