Jump to content
It's_Matra

Anyone help with this python issue?

Recommended Posts

Hi all,

 

I have an issue when trying to set a variable folder location... 

if counter <= animLength:
            sixthMarker.texture = BigWorld.PyTextureProvider('scripts\\client\\mods\\sixthSense\\' + fileName + str(counter) + fileFormat)
            counter += 1
            callbackSpeed = 1.0 / (speed * 2)
            BigWorld.callback(callbackSpeed, showSixth)

That currently works as file name (minus the counter number) and format are defined in an xml file like below

	<fileName>Sixth_</fileName>
	<fileFormat>.dds</fileFormat>

These are set in the python script

		xmlfile = ResMgr.openSection('../res_mods/configs/sixthSense/sixthSense.xml')
		static = xmlfile.readBool('oneFrame')
		stayTime = xmlfile.readFloat('stayTime')
		fileName = xmlfile.readString('fileName')
		fileFormat = xmlfile.readString('fileFormat')
		speed = xmlfile.readFloat('speed')
		animLength = xmlfile.readInt('animLength')
		sizeX = xmlfile.readInt('sizeX')
		sizeY = xmlfile.readInt('sizeY')
		createSixth()

That all works just fine, but what I want to do is change the location via an address set in the xml file...

 

So I added a 'fileLocation' (sensible name) to the xml file

		xmlfile = ResMgr.openSection('../res_mods/configs/sixthSense/sixthSense.xml')
		static = xmlfile.readBool('oneFrame')
		stayTime = xmlfile.readFloat('stayTime')
		fileLocation = xmlfile.readString('fileLocation')
		fileName = xmlfile.readString('fileName')
		fileFormat = xmlfile.readString('fileFormat')
		speed = xmlfile.readFloat('speed')
		animLength = xmlfile.readInt('animLength')
		sizeX = xmlfile.readInt('sizeX')
		sizeY = xmlfile.readInt('sizeY')
		createSixth()
	<fileLocation>scripts\\client\\mods\\sixthSense\\</fileLocation>
	<fileName>Sixth_</fileName>
	<fileFormat>.dds</fileFormat>

Then changed the location of the file(s) to

        if counter <= animLength:
            sixthMarker.texture = BigWorld.PyTextureProvider(fileLocation + fileName + str(counter) + fileFormat)
            counter += 1
            callbackSpeed = 1.0 / (speed * 2)
            BigWorld.callback(callbackSpeed, showSixth)

Now that to me should piece together the location - which (as set in the xml file) should be:

 

scripts\\client\\mods\\sixthSense\\Sixth_(counterNumber).dds

 

which is exactly the same as the original location (which does work!), except this method doesn't seem to work...

 

My Python skills aren't l33t by any imagination but I can't see what could be causing that issue! Anyone able to help!?

Share this post


Link to post
Share on other sites

The double backslashes are used to escape a single backslash. When the string is read from the XML file, no escaping is performed. So, you are literally using double backslashes in the path. Change the XML <fileLocation> tag to this:

scripts\client\mods\sixthSense\
I try to stick to UNIX-style paths ('/' instead of '\') whenever possible to avoid this crap. You can also begin string liberals with an 'r' to disable escape codes (e.g. r'scripts\client\mods\sixthSense\' == 'scripts\\client\\mods\\sixthSense\\').

Share this post


Link to post
Share on other sites

Tried that and still no joy, it throws up 'texture not found' error (in game) as it can't find the file it's looking for...

 

There is no error in the log nor when running the script, it just simply can't seem to look in that location... maybe I have to do some more digging around in BigWorld?

 

(sorry my explanation wasn't very good in my first post - written early this morning!).

 

The script compiles/runs fine and chucks up errors as/when it should including the texture not found error when it can't find a file... but from what I did it should be no different to what it was prior... should it?

 

 

Tell a lie... cleared the error log then ran it again and found this:

 

NameError: global name 'fileLocation' is not defined... fml

 

I forgot to add it lol

 

global fileFormat
global fileLocation

 

 

EDIT/UPDATE: Now I have a new error... TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' for the line

sixthMarker.texture = BigWorld.PyTextureProvider(fileLocation + fileName + str(counter) + fileFormat)

Share this post


Link to post
Share on other sites

It now thinks that fileLocation value is 'None'

 

Are there any limitations to strings in Python? does it matter that the string has 'special characters' - namely / or \ ? It has no trouble with the single settings like fileName or type (which have _ and . respectively)

		fileLocation = xmlfile.readString('fileLocation')
		fileName = xmlfile.readString('fileName')
		fileFormat = xmlfile.readString('fileFormat')

fileLocation like the other strings are set to None by default at the start of the file

fileLocation = None
fileName = None
fileFormat = None

It's almost as if it can't read the data from the xml file  :O

Share this post


Link to post
Share on other sites

Haven't forgotten about this or updated anything, have been away from my machine and WoT for a while. I had a new idea to try first which was I know the xml file is being read correctly on fileName so why have an extra variable... just put the whole thing in one bit (fileLocation and fileName combined into just fileName).

 

sixthMarker.texture = BigWorld.PyTextureProvider(fileName + str(counter) + fileFormat)

 

Will see how I get on with that when I get chance

Share this post


Link to post
Share on other sites

Special characters always cause some issues in XML, have you tried wrapping the path with the CDATA tag?  See example below.

 

<fileLocation><![CDATA[scripts\client\mods\sixthSense\]]></fileLocation>

Share this post


Link to post
Share on other sites

^^ this makes sense but....

 

 

 

sixthMarker.texture = BigWorld.PyTextureProvider(fileName + str(counter) + fileFormat)

 

 

This idea worked just fine, why I didn't think of this before is beyond me as it's so much more simple and reduces code size!

 

Now to play around with what locations I can/can't use!

 

changed the xml file to:

<fileName>scripts\\client\\mods\\sixthSense\\Sixth_</fileName>

Will see what changes/effects path styles have on it too now that I have it working!!

 

 

Thank you all for your help

 

 

 

EDIT: It doesn't like looking outside of the 0.9.6 directory...

 

By default it starts in the 0.9.6 folder but by trying to send it up a level using .. it doesn't seem to like it... maybe a bigworld/res_mods issue??

..\\mods\\shared_resources\\sixthSense\\Sixth_ returns nothing...

Share this post


Link to post
Share on other sites

By default it starts in the 0.9.6 folder but by trying to send it up a level using .. it doesn't seem to like it... maybe a bigworld/res_mods issue??

..\\mods\\shared_resources\\sixthSense\\Sixth_ returns nothing...

I think it is probably an intentional sandbox for security reasons. Otherwise mod could just read anything on your drive.

Share this post


Link to post
Share on other sites

I think it is probably an intentional sandbox for security reasons. Otherwise mod could just read anything on your drive.

 

This sounds highly likely.

Share this post


Link to post
Share on other sites

Yeah I though it would be... I was hoping I would be able to use the much more useful/helpful file structure that XVM uses so updates can be drastically reduced in size but oh well... at least I know now that it can't be done!

 

Thank you all for your help though :)

Share this post


Link to post
Share on other sites

I can get the mods to look at an external address and view code/resources from a website but I can't get it to look at localised files/folders outside of the directory - saying that I have trouble editing stuff unless I run notepad++ as admin and even then have to close the file to make changes sometimes... my rights are a bit screwy

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...