[SCRIPTING HELP] "append_to_list" in iterations ?

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

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

PSCO1
Posts: 1087
Joined: Thu, 4. Jun 09, 17:08
x4

[SCRIPTING HELP] "append_to_list" in iterations ?

Post by PSCO1 » Sat, 4. Nov 23, 02:12

Hello
Im going to do my own script about hull repairs

But I don't know how to deal with arrays in iterations and try to add elements in an external array

Code: Select all

...
...
...
<do_all exact="$npcs.count" counter="$i">
	<set_value name="$npc" exact="$npcs.{$i}"/>
	<set_value name="$engValue" exact="$npc.skill.engineering"/>
	<set_value name="$morValue" exact="$npc.skill.morale"/>
	<set_value name="$workForce" exact="$workForce + $engValue + $morValue"/>
...
...
...

OR

...
...
...
<set_value name="$workForceList" exact="[]"/>
<do_all exact="$npcs.count" counter="$i">
	<set_value name="$engValue" exact="$npc.skill.engineering"/>
	<set_value name="$morValue" exact="$npc.skill.morale"/>
	<append_to_list name="$workForceList" exact="$engValue"/>
	<append_to_list name="$workForceList" exact="$morValue"/>
...
...
...

<set_value name="$workForce" exact="$workForce / $npcs.count"/>
At this status, my script set my "$workForce" value to 15, (the count of my ship crew), thats not I want :(
This value must be 17.3333...
Is this the correct syntax to get NPC skills ?
And how to additionate all elements in "$workForceList" ?

User avatar
Dj_FRedy
Posts: 237
Joined: Mon, 27. Jun 11, 05:58
x4

Re: [SCRIPTING HELP] "append_to_list" in iterations ?

Post by Dj_FRedy » Sat, 4. Nov 23, 19:11

Hello there
Some examples of how to get, store and retrieve values for your purpose.

Code: Select all

<set_value name="$Controllable" exact="player.ship"/>
<set_value name="$PeopleList" exact="$Controllable.people.list"/>
<set_value name="$workForce" exact="0"/>

<set_value name="$SkillTable" exact="table[]"/>
<do_all exact="$PeopleList.count" counter="$i">
    <set_value name="$npctemplate" exact="$PeopleList.{$i}"/>
    <set_value name="$engValue" exact="$Controllable.people.{$npctemplate}.skill.engineering"/>
    <set_value name="$workForce" exact="$workForce + $engValue"/>

    <set_value name="$SkillTable.{$i}" exact="table[ $npc = $npctemplate, $engValue = $engValue ]"/>
</do_all>

<do_all exact="$SkillTable.keys.count" counter="$i">
    <set_value name="$npc" exact="$SkillTable.{$i}.$npc"/>
    <set_value name="$engValue" exact="$SkillTable.{$i}.$engValue"/>
    <debug_text text="'npc: ' + $npc + ', engValue: ' + $engValue" chance="100"/>
</do_all>

<set_value name="$SkillList" exact="[]"/>
<do_for_each name="$npctemplate" in="$PeopleList">
    <set_value name="$engValue" exact="$Controllable.people.{$npctemplate}.skill.engineering"/>
    <set_value name="$workForce" exact="$workForce + $engValue"/>

    <append_to_list name="$SkillList" exact="table[ $npc = $npctemplate, $engValue = $engValue ]"/>
</do_for_each>

<do_for_each name="$element" in="$SkillList">
    <set_value name="$npc" exact="$element.$npc"/>
    <set_value name="$engValue" exact="$element.$engValue"/>
    <debug_text text="'npc: ' + $npc + ', engValue: ' + $engValue" chance="100"/>
</do_for_each>
"All my contributions to the Technical Support and Public Beta Feedback sections will be concise and to the point, no diatribes, that's what the other sections are for".
Thank you for your efforts.

PSCO1
Posts: 1087
Joined: Thu, 4. Jun 09, 17:08
x4

Re: [SCRIPTING HELP] "append_to_list" in iterations ?

Post by PSCO1 » Sat, 4. Nov 23, 20:18

Awesome ! Thanks :)

Return to “X4: Foundations - Scripts and Modding”