how to compare strings?

Users who are viewing this thread

i want to sort my heroes list based on their names. If I store hero 1's name to s1 and hero 2's name to s2, can gt or lt operation be used to make comparation between s1 and s2? 
 
dunde said:
i want to sort my heroes list based on their names. If I store hero 1's name to s1 and hero 2's name to s2, can gt or lt operation be used to make comparation between s1 and s2?
You'd have to use real Python code. I don't know of any MnB-defined operation that would be able to compare strings. Same goes for the character comparisons.

You might be able to sort strings by length using real-Python len(), but that doesn't work so well...

C++ has quite a bit of string comparers, like strcmp(s1,s2), and real Python should do too.
 
You can't use real python code as that would only work precompile.

Why not sort of them in alphabetical order as they are entered into the module system, then you can compare them normally with the gt and lt operations as each one will be assigned an ID (lower in the list, higher ID)
 
I think that will be not as simple as reorder them at module_troops.py. If the heroes include all companions, all kingdom lords and kingdom family members, reorder them will make us have to edit the scripts that use range like kingdom_heroes_begin and kingdom_heroes_end.
But you gave me the idea, we should sort them with another paramater. I think we can give them an additional slot according to their name in alphabetical order.
Thanks..
 
Back
Top Bottom