[HELP MD] Issues with add_build_to_expand_station command

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

User avatar
RoverTX
Posts: 1466
Joined: Wed, 16. Nov 11, 18:37
x4

[HELP MD] Issues with add_build_to_expand_station command

Post by RoverTX »

Trying to write an MD to find all Xenon Wharfs and Shipyards and get them to build on a solar power plant.

Here is what I have so far.

https://gist.github.com/rovermicrover/2 ... 0646c1d64e

It successfully loops through all the xenon stations and attempts to kick off the builds but... I have two problems.

The lookup on line 18 always fails with the following error

Code: Select all

[=ERROR=] 1517198.24 Error in MD cue md.XenonDurability.EnsureSolarPowerPlants<inst:b6a4c>: Property lookup failed: $ConstructionPlan.{16}.macro.products
* Expression: $ConstructionPlan.{$plan_i}.macro.products.list.indexof.{ware.energycells}
It blows up on the build task created by add_build_to_expand_station on line 31 with the error

Code: Select all

[=ERROR=] 1517198.24 Error in AI script build.buildstorage on entity 0x419f7: <process_build />: Build Task could not be successfully processed by the BuildProcessor
* Expression: $build
Been banging my head against the wall for a while and I think I am just missing something obvious but a fresh pair of eyes would be a great help!
User avatar
RoverTX
Posts: 1466
Joined: Wed, 16. Nov 11, 18:37
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by RoverTX »

Solved the build failing. Was passing in its ware not its macro. Still can't figure out the lookup issue.
Mysterial
Posts: 664
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by Mysterial »

Probably some module macros don't have a 'products' property. If you look at the macro type definition in scriptproperties.xml many of them only exist for certain types of macros. You can try logging more macro data to figure out in which cases the variable exists, or you can just put @ in front of the whole expression to suppress errors. (Of course, the latter way makes it more difficult to catch typos and such, so you should make sure it works correctly for known production modules first)
User avatar
RoverTX
Posts: 1466
Joined: Wed, 16. Nov 11, 18:37
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by RoverTX »

Put in some checks for that but it was still failing on every lookup. Turns out it’s an id lookup which for non random stations that have construction plans isn’t simply numeric it looks like. Didn’t feel like trying to figure that out so stopped looking at the plan sequence and just asked for the stations production.
Mysterial
Posts: 664
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by Mysterial »

Well, FactionLogic_Economy.xml has this and it doesn't generate errors:

Code: Select all

<set_value name="$ConstructionPlan" exact="$Stations.{$i}.plannedconstruction.sequence"/>
<do_if value="$ConstructionPlan">
  <do_all exact="$ConstructionPlan.count" counter="$plan_i">
	<do_if value="$ConstructionPlan.{$plan_i}.macro.isclass.production">
	  <do_if value="$ConstructionPlan.{$plan_i}.macro.products.list.indexof.{$Ware}">
		<do_if value="not $Stations.{$i}.planmodule.{$ConstructionPlan.{$plan_i}.id}.isoperational">
		  <set_value name="$ProductionPlanned" exact="true"/>
		  <debug_text text="$DebugText + 'Station ' + $Stations.{$i} + ' ' + $Stations.{$i}.knownname + ' in sector ' + $RequestSector + ' ' + $RequestSector.knownname + ' already has a planned production module for ' + $Ware + ' in its construction plan (may be planned, under construction or wrecked). Do not attempt to build another just yet.'" context="false" chance="$DebugChance"/>
		  <break/>
		</do_if>
	  </do_if>
	</do_if>
  </do_all>
</do_if>
Yours complaining every iteration is probably just because most Xenon stations have zero production modules.

However, as you note it's not really necessary to look through the construction plan unless you want to catch modules that haven't been built yet.
User avatar
RoverTX
Posts: 1466
Joined: Wed, 16. Nov 11, 18:37
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by RoverTX »

I actually found that and refactored it for my own purposes and still got the offset error. Thats why I assumed going through a plan like that must only work for non planned stations. IE plan old factories.

Sorry didn't mean to be "complaining"
Mysterial
Posts: 664
Joined: Wed, 6. Nov 02, 20:31
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by Mysterial »

I was referring to game "complaining" to the log, not your text ;)
Xenon_Slayer
EGOSOFT
EGOSOFT
Posts: 13126
Joined: Sat, 9. Nov 02, 11:45
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by Xenon_Slayer »

The $macro.products property will only work for production module macros (we'll improve the documentation for that property). Just tested with that additional check and didn't get any errors. Note, a shorter way to check a product ware is .products.{$Ware}.exists
Come watch me on Twitch where I occasionally play several of the X games
User avatar
RoverTX
Posts: 1466
Joined: Wed, 16. Nov 11, 18:37
x4

Re: [HELP MD] Issues with add_build_to_expand_station command

Post by RoverTX »

Thanks Xenon Slayers that is what I ended up doing!

Return to “X4: Foundations - Scripts and Modding”