Modding Q&A [For Quick Questions and Answers]

Users who are viewing this thread

Status
Not open for further replies.
SOLVED: http://forums.taleworlds.com/index.php/topic,6575.msg7294796.html#msg7294796

Basic python question:

How can I make a module_string entry for each module_scene entry automatically, using the ID of said scene.

Code:
  ("mp_village_plains_1", sf_generate, "none", "none", (0,0),(100,100),-100,"0x0000000030068500800258960000749200006460000070a4",
    [],[],"outer_terrain_plain"),
  ("mp_village_plains_2", sf_generate, "none", "none", (0,0),(100,100),-100,"0x0000000030068500800258960000749200006460000070a4",
  [],[],"outer_terrain_plain"),
  ("mp_village_desert_1", sf_generate, "none", "none", (0,0),(100,100),-100,"0x0000000030068500800258960000749200006460000070a4",
  [],[],"outer_terrain_desert"),
  ("mp_village_desert_2", sf_generate, "none", "none", (0,0),(100,100),-100,"0x0000000030068500800258960000749200006460000070a4",
  [],[],"outer_terrain_desert"),

I would like to this to be added at the bottom of strings automatically
Code:
  ("mp_village_plains_1", "mp_village_plains_1"),
  ("mp_village_plains_2", "mp_village_plains_2"),
  ("mp_village_desert_1", "mp_village_desert_1"),
  ("mp_village_desert_2", "mp_village_desert_2"),

Reason: I'm using a scene debugger, which only shows ID's of scenes as numbers currently (555, 556, 557, etc.) and I'd like this to be the scene name that's also used in the obj file as scn_*name*.obj where *name* is what I'd like to show instead of those numbers.

I know with some basic python this should be easily do-able and would prevent me from copying it all manually and manually create these strings all the time.


--
Just to clarify: I mean actual Python code, not M&B MS code (which wouldn't be possible anyways, afaik)

Something like this, but I need help with the actual creation of the module_strings part.
Code:
for x in range(mp_village_plains_1, mp_village_desert_2 + 1):
print "(\"x\", \"x\"),"
 
I am neither a regular user, nor experienced with Python, but I believe it should look something like:
Code:
(str(x), str(x)) for x in range(mp_village_plains_1, mp_village_desert_2 + 1):
I didn't quite get what you want the resulting strings to look like, just used your example as a basis.
 
I'll try that. I suppose I'll need to import ID_scenes then, to module_strings

EDIT:

After learning myself the basics of Python I ended up with:

Code:
for x in range(scn_mp_camp, scn_mp_scenes_end):
  strings.append((str(x), str(x)))

The function works fine, but it creates the following string (String id: 555, String definition: 555):
Code:
("555", "555")

But I want:
Code:
("mp_camp", "mp_camp")

EDIT2:
Found this code in process_scenes
Code:
  for i_scene in xrange(len(scenes)):
    ofile.write("scn_%s = %d\n"%(convert_to_identifier(scenes[i_scene][0]),i_scene))

Might be able to turn this into
Code:
for i_scene in xrange(len(scenes)):
    strings.append("scn_%s\n"%(convert_to_identifier(scenes[i_scene][0])
 
@minnakodunum you can google for python tutorials...no needing to make basic ones.

For the actual problem, I think  you should have this
for x in range(scn_mp_camp, scn_mp_scenes_end):
  strings.append((str(scenes[ x ][0]), str(scenes[ x ][0])))

scenes[ x ][0] holds the scene id. If it would be 1 instead of 0, it would be the flags; if it would be 2, it would be the mesh name and so on.

I think that you can get rid of the str(), because the scenes already have the first parameter as string.
Make sure to include module_scenes in the process of where this code goes.
 
Arch3r said:
The function works fine, but it creates the following string (String id: 555, String definition: 555):
TBH that's what you had in your example, and I apparently couldn't figure what you really wanted out. :razz:
The_dragon's code should do the trick. Not sure if it should be "append" or "extend", though. I believe I remember Caba'drin saying that one should usually use "extend", but I'm not certain.
 
append adds to the bottom of the array, which is what I'd want

EDIT: Alright, that worked perfectly, just had to import module_scenes, thanks a bunch!

Just pasting the solution again for others, if they ever need something similar:
Code:
for x in range(scn_mp_camp, scn_mp_scenes_end):
  strings.append((str(scenes[ x ][0]), str(scenes[ x ][0])))

Just paste at the end of module_strings (without indents!), under the ]

Then from module_scenes import * at the top of the file under the # -*- coding: cp1254 -*- whatever that may be.
 
Arch3r said:
... under the # -*- coding: cp1254 -*- whatever that may be.
It's just a character encoding of some sort that some files seem to need. Can't really tell you what it is about though. Windows-1254, I reckon. Cyrillic used to use Windows-1251, so maybe 1254 contains some special formatting symbols or something.
Also, for the protocol, you don't really need the spaces in front of and after the "x" in the square brackets. :smile:
 
Nuchiha said:
Is there a max weight on items? I set a "wine barrel" to 136-kilograms but ingame it appears as 8.0
There is an arbitrary item weight maximum of 63.75 (one 0.25 step less than 2^6) imposed by the implementation of the Python module system, but in the item_kinds1.txt file of the module, the weight is unpacked into an individual number that probably has a much higher limit (imposed by the engine code structure). So, you could either remember to change the weight number in item_kinds1.txt after each time you build your module, or you could try change the format used by the Python code when compiling the module system, similar to how it was done for the PW module, commit linked here.

The weight of the wine barrel is 8.0 because the higher bits of the binary representation were discarded (truncated).
 
Lumos said:
Also, for the protocol, you don't really need the spaces in front of and after the "x" in the square brackets. :smile:

You are right, but the spaces are needed here, in the replies, because if you put '[' then 'x' then ']', you will see a black square like this [x] :grin:
 
Vornne said:
Nuchiha said:
Is there a max weight on items? I set a "wine barrel" to 136-kilograms but ingame it appears as 8.0
There is an arbitrary item weight maximum of 63.75 (one 0.25 step less than 2^6) imposed by the implementation of the Python module system, but in the item_kinds1.txt file of the module, the weight is unpacked into an individual number that probably has a much higher limit (imposed by the engine code structure). So, you could either remember to change the weight number in item_kinds1.txt after each time you build your module, or you could try change the format used by the Python code when compiling the module system, similar to how it was done for the PW module, commit linked here.

The weight of the wine barrel is 8.0 because the higher bits of the binary representation were discarded (truncated).

That also explains why the "wine keg" was set down from "68" to whatever number it was.

Can I have permission to use your code? Even if it's a small tweak, I don't want to steal or copy someone's work w/o at getting permission from them. Which python file is the code in? There's some 118 files and I'd hate to sift through them all.

And thanks Vornne, doubly so for giving me an exact measurement of the limit. If I can't use it I'll at least know to stay under it, I really hate editing the ".txt" files.
 
Nuchiha said:
Can I have permission to use your code? Even if it's a small tweak, I don't want to steal or copy someone's work w/o at getting permission from them. Which python file is the code in? There's some 118 files and I'd hate to sift through them all.
Yes, go ahead and use it: the entire PW module system has been released to the public for use under a few conditions (basically: give credit, don't impersonate PW with the mod name), but for such a simple little tweak don't worry about the credit. In case you are wondering, the new weight maximum using the tweak should be 16383.75, by my calculation.

The file the changes apply to is listed on that page - header_items.py. Since the other changes from Native in that file are minimal, you might get away just downloading that file (click the "view" button) to replace the Native header_items.py; otherwise, remove the red lines and add the adjacent green lines to replace them, without the "+" and line numbers at the start of each.
 
Vornne said:
Nuchiha said:
Can I have permission to use your code? Even if it's a small tweak, I don't want to steal or copy someone's work w/o at getting permission from them. Which python file is the code in? There's some 118 files and I'd hate to sift through them all.
Yes, go ahead and use it: the entire PW module system has been released to the public for use under a few conditions (basically: give credit, don't impersonate PW with the mod name), but for such a simple little tweak don't worry about the credit. In case you are wondering, the new weight maximum using the tweak should be 16383.75, by my calculation.

The file the changes apply to is listed on that page - header_items.py. Since the other changes from Native in that file are minimal, you might get away just downloading that file (click the "view" button) to replace the Native header_items.py; otherwise, remove the red lines and add the adjacent green lines to replace them, without the "+" and line numbers at the start of each.

Thank you, Vornne. And I'm giving you credit anyways, it's only fair and it helped me a lot. 16,000+ kilos would be a lot of weight, don't know what could feasibly weigh that much in a person's baggage train. Thanks again, you removed this troublesome limit from me.

-----

I've come under another snag, the "ammunition" box of food, or the amount. I've decided that each "tick" fed one person's meal, and there'd be 3 in a day (breakfast, lunch and dinner). Naturally I've gotten some large food measurements, such as a barrel of ale (288 "ticks" or pints), however it defaults to some number that I forgot to record. However, the demi-barrel (keg) is stable at "144" ticks. I could probably do with removing barrels, but I would rather not as they can be used as cheap trade-goods.

I'll be seeing if the problem is similar to the weight, if so, I can "reverse-engineer" the solution Vornne gave me and apply it.
 
The_dragon said:
[x]... Didn't know that. Holy ****. :lol:
However, it doesn't work if it's in a [ code] block, just like all the other bbcode tags. :grin:

Nuchiha said:
I'll be seeing if the problem is similar to the weight, if so, I can "reverse-engineer" the solution Vornne gave me and apply it.
Just be certain, like every other time you're tinkering with the ModSys, that the bits you're overwriting are not used by anything else, or you might get very strange results.
 
What is the difference between str_store_string and str_store_string_reg ? Oh s**t. It copies one string to another.

And how to use send_message_to_url operation?Do we only can send a string to an url ?
 
I have this issue where faces are white from a distance but when you get nearer their faces turn normal. It's kinda annoying and when i enter a room with lots of people there are white faces everywhere. This just happens with some new faces I added. What did i do wrong?
 
Status
Not open for further replies.
Back
Top Bottom