Community Forum

Using a custom pallet.xml only works with an absolute path

Forum Overview >> Scripting

CategoryScripting
Created06.12.2021 13:58


dxtr66 06.12.2021 13:58
I'd like a custom chicken barn to spawn other pallets. Did that by extracting the chicken barn & creating a new mod with it. I also added the 'standard' chickenBoxPallet to that mod with some adjusted values. Everything is directly in the mod directory, no subdirs...as easy as possible.
Now I saw in the XSD that you can specify a <pallet filename=""/> as subtag of the pallets tag in the husbandry section. Did that, looks like this:

....
<husbandry>
...
<pallets fillType="EGG" maxNumPallets="8" unitText="$l10n_unit_pieces">
<spawnPlaces>
<spawnPlace startNode="palletArea1Start" endNode="palletArea1End" />
<spawnPlace startNode="palletArea2Start" endNode="palletArea2End" />
</spawnPlaces>
<pallets>
<pallet filename="C:/Users/bla/Documents/My Games/FarmingSimulator2022/mods/FS22_testMod/eggBoxPallet.xml" />
</pallets>
</pallets>
...

First of all - that works like a charm. No problem, my customized pallet is spawning just fine.

But of course my problem is, as you can see...thats a full path there for the pallet.xml. Of course thats only working for me. Normally I would just reference the file relative - but that does not work. I tried several options - here is what I tried...I always get the same error:

<pallet filename="eggBoxPallet.xml" />
<pallet filename="./eggBoxPallet.xml" />
<pallet filename="$modDir$/FS22_testMod/eggBoxPallet.xml" />
<pallet filename="$modDir$FS22_testMod/eggBoxPallet.xml" />
<pallet filename="$modDir/FS22_testMod/eggBoxPallet.xml" />
<pallet filename="$moddir$/FS22_testMod/eggBoxPallet.xml" />
<pallet filename="$moddir$FS22_testMod/eggBoxPallet.xml" />
<pallet filename="$moddir/FS22_testMod/eggBoxPallet.xml" />
<pallet filename="$mapdir$/eggBoxPallet.xml" />

Here is one instance of the error I am getting:
2021-12-02 17:28 Error: Failed to open xml file 'mapdir$/eggBoxPallet.xml'.
2021-12-02 17:28 Error: Failed to open xml file 'mapdir$/eggBoxPallet.xml'.
2021-12-02 17:28 Error: Running LUA method 'loadSharedI3DFileAsyncFinished'.
2021-12-02 17:28 dataS/scripts/vehicles/specializations/FillUnit.lua(2672) : attempt to index local 'xmlFile' (a nil value)

Has anyone an idea how to proceed here? I am pretty sure that it 'should' work (as it does perfectly fine with an absolute path), it looks to me like the filename attribute of the pallet tag does not support what other filename tags do (variables, starting dir for relative paths...). IMO it looks like a bug.

Any idea how I could solve this differently? Would that be possible with some scripting?

Bilbo Beutlin (BBeutlin) 06.12.2021 21:38
Placeholders like $mapdir$ are only allowed in the map's files defaultVehiclesXMLFilename, defaultPlaceablesXMLFilename, defaultItemsXMLFilename.
For all other you must use path descriptions relative to the mod/map root folder.
It is wise to use the default Giants folder hierarchy. There might be internal references you didn't notice yet.

So it should be something like
<pallet filename="objects/pallets/myPallet.xml" />
where you have your xml and i3d.

Your "myPallet.xml" then must point to
<filename>objects/pallets/myPallet.i3d</filename>

dxtr66 07.12.2021 17:08
Mh..many thanks for your reply. I tried that, but its still the same.

Just to be sure - here is what I changed.

I moved all stuff regarding the pallets to "objects/pallets/theBetterEggPallet" in my mod. i also renamed the files to 'theBetterEggPallet.xml' etc. :) - the placeable (chickenBarn) was moved to a folder placeables in my mod.

Adapted all paths - just as an example the path to the pallet in the placeable.
<pallet filename="objects/pallets/theBetterEggPallet/theBetterEggPallet.xml"></pallet>

Also the paths in the moddesc of course

<storeItems>
<storeItem xmlFilename="placeables/chickenBarnSmall.xml"/>
<storeItem xmlFilename="objects/pallets/theBetterEggPallet/theBetterEggPallet.xml"/>
</storeItems>

-> same error as above.

2021-12-07 17:04 Error: Failed to open xml file 'objects/pallets/theBetterEggPallet/theBetterEggPallet.xml'.
2021-12-07 17:04 Error: Failed to open xml file 'objects/pallets/theBetterEggPallet/theBetterEggPallet.xml'.
2021-12-07 17:04 Error: Running LUA method 'loadSharedI3DFileAsyncFinished'.
2021-12-07 17:04 dataS/scripts/vehicles/specializations/FillUnit.lua(2672) : attempt to index local 'xmlFile' (a nil value)

Just as a test, I changed the one path to the pallets back to an absolute one...and everything works like a charm.

<pallet filename="C:/Users/bla/Documents/My Games/FarmingSimulator2022/mods/FS22_testMod/objects/pallets/theBetterEggPallet/theBetterEggPallet.xml"></pallet>

But of course thats no solution for me :( .

Bilbo Beutlin (BBeutlin) 08.12.2021 04:20
As I see, you have done everything right.
But regarding the cross-references in the FS xml files, there are obviously still many errors in consistence.
Will not help you, but you are not the only one who suffers with this.
FS22 made a step forward in features, but more backstep in modding ability.
Thanks @Giants for this inconsistent and shitty filepath/name resolving.

William Rowe (Bonger76) 14.12.2021 19:10
sorry thought I saw a problem but was reading it wrong.


Espen K. (estyx) 14.12.2021 22:07
It seems that they have removed all forms of using variables in paths..
So for now the only way to get a similar functionality would be to overwrite

function Utils.getFilename(filename, baseDir)

It returns two variables: string, boolean
Where the string is the full path (if valid), and the boolean is whether it baseDir is valid or not.
The latter variable is used by some functions, but mostly only the path value is used. So if you end up overwriting the function, keep that in mind to maintain compatability.
Safest bet is to overwrite it only when you detect a specific pattern in the string that is yours, otherwise return superFunc(...)


Note: Log in to post. Create a new account here.