How to explain <set_value> without exact?

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

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

Post Reply
EGOiNahoo
Posts: 7
Joined: Tue, 27. Sep 22, 21:00

How to explain <set_value> without exact?

Post by EGOiNahoo » Fri, 30. Sep 22, 11:35

I try to find case and explain from https://www.egosoft.com:8444/confluence ... ctor+Guide, but maybe i miss something?

When i read restock logic, there is

Code: Select all

<actions name="ResupplyCheck">
        <set_value name="$orders_interrupt" exact="this.ship.orders"/>
        <do_if value="this.ship.defaultorder.exists">
          <append_to_list name="$orders_interrupt" exact="this.ship.defaultorder"/>
        </do_if>
        <do_all exact="$orders_interrupt.count" counter="$counter_lib_orders">
          <do_if value="(($orders_interrupt.{$counter_lib_orders}.id == 'Equip') or ($orders_interrupt.{$counter_lib_orders}.id == 'Repair') or ($orders_interrupt.{$counter_lib_orders}.id == 'RestockSubordinates')) and $orders_interrupt.{$counter_lib_orders}.state != orderstate.started">
            <debug_text text="'%1 (%2) is already heading to dock with a %3 order. No need to check for resupply again.'.[this.ship.knownname, this.ship, $orders_interrupt.{$counter_lib_orders}.id]" chance="$debugchance_interrupt"/>
            <set_value name="$cleanup_interrupt"/>
            <break/>
          </do_if>
        </do_all>
        <remove_value name="$orders_interrupt"/>
Line 9

Code: Select all

	<set_value name="$cleanup_interrupt"/>
Is $cleanup_interrupt got value from some context? how it work?

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1868
Joined: Mon, 23. Nov 15, 18:02

Re: How to explain <set_value> without exact?

Post by j.harshaw » Fri, 30. Sep 22, 12:33

value that is set to the defined variable defaults to 1. quoted notation is a shortcut that i sometimes use when the precise value doesn't matter in usage as long as it is neither null nor 0. it's frowned upon.

EGOiNahoo
Posts: 7
Joined: Tue, 27. Sep 22, 21:00

Re: How to explain <set_value> without exact?

Post by EGOiNahoo » Fri, 30. Sep 22, 14:07

j.harshaw wrote:
Fri, 30. Sep 22, 12:33
value that is set to the defined variable defaults to 1. quoted notation is a shortcut that i sometimes use when the precise value doesn't matter in usage as long as it is neither null nor 0. it's frowned upon.
Got it!
I was tried to infer which value from parent is seems to assign to this XD. Now I finally understand!

EGOiNahoo
Posts: 7
Joined: Tue, 27. Sep 22, 21:00

Re: How to explain <set_value> without exact?

Post by EGOiNahoo » Sat, 1. Oct 22, 12:44

j.harshaw wrote:
Fri, 30. Sep 22, 12:33
value that is set to the defined variable defaults to 1. quoted notation is a shortcut that i sometimes use when the precise value doesn't matter in usage as long as it is neither null nor 0. it's frowned upon.
My problems appeared one and another.


--- 1. what is "this" ?
I notice that it used as `this.ship / this.assignedcontrolled / this.isplayerowned` , is it an entity? It represent the unit which trigger script when script running?


--- 2. what is "interrupt"?
I explain it as "a break for something" at begin, but than I found much usage like "$ammotable_interrupt","cleanup_interrupt","pass_interrupt"
It means any reality entiry ? or just a code naming standard?


--- 3. what is different between counter and countermeasure?

Code: Select all

<set_value name="$missilesneeded_interrupt" exact="$missiles_numneeded_interrupt gt (this.ship.ammostorage.missile.capacity * 0.7)" />
<set_value name="$countermeasuresneeded_interrupt" exact="$countermeasures_numneeded_interrupt gt (this.ship.ammostorage.countermeasure.capacity * 0.7)" />
Here the author calculate both of them, It seems will gain two different value.

--- 4. what is "macro"?
I find few description but many appears on some ingame-value change. It seems to a proxy to handler ingame-value?

Code: Select all

<evaluate_missile_storage object="this.assignedcontrolled" level="$loadoutlevel_interrupt" amounts="$output_ammoamounts_interrupt" macros="$output_ammomacros_interrupt" />
this function offer two values as amounts and macros, but for calculate number of missle needed just need `ammostorage.missile.capacity - ammostorage.{$targetcate}.count` in my opinion.

--- 5. how the script work?

I think a whole resupply may includes 'check ammo' - 'find supply station/ship' - 'fly and dock' - 'apply supply'
File 'interrupt.restock.xmd' ending with 'clamp_equipment_amount / add_build_to_modify_ship / create_order(RestockSubordinates)'.

The command 'clamp_equipment_amount / add_build_to_modify_ship' apply game-value change directly ? or just create a interal "fly and dock and apply" order like a blackbox ?

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1868
Joined: Mon, 23. Nov 15, 18:02

Re: How to explain <set_value> without exact?

Post by j.harshaw » Sat, 1. Oct 22, 13:39

EGOiNahoo wrote:
Sat, 1. Oct 22, 12:44
--- 1. what is "this" ?
I notice that it used as `this.ship / this.assignedcontrolled / this.isplayerowned` , is it an entity? It represent the unit which trigger script when script running?
in AI scripts, 'this' is the entity executing the script. usually ship pilots or station managers, but they can also be computers running specific aspects of a more complex ship such as turret and drone control.

note that in MD, 'this' refers to a cue rather than something corporeal in-game.
EGOiNahoo wrote:
Sat, 1. Oct 22, 12:44
--- 2. what is "interrupt"?
I explain it as "a break for something" at begin, but than I found much usage like "$ammotable_interrupt","cleanup_interrupt","pass_interrupt"
It means any reality entiry ? or just a code naming standard?
interrupt handlers are bits of logic that run in the context of other scripts. in such a case, there's a danger that that code could disrupt the normal operation of the script in which it is running if it happens to have variables that have the same names since these variables would overwrite the variables in the contextual script. the "_interrupt" suffix in this case is just a safety mechanism to make sure that that disruption won't happen. in practice, i later changed to simply adding an underscore before the variable name (for example, $_ship in interrupts or libraries vs $ship in main AI scripts).

these don't constitute conventions that anyone tries to enforce in any way, but are rather just practices that i've come up with over the years.
EGOiNahoo wrote:
Sat, 1. Oct 22, 12:44
--- 3. what is different between counter and countermeasure?

Code: Select all

<set_value name="$missilesneeded_interrupt" exact="$missiles_numneeded_interrupt gt (this.ship.ammostorage.missile.capacity * 0.7)" />
<set_value name="$countermeasuresneeded_interrupt" exact="$countermeasures_numneeded_interrupt gt (this.ship.ammostorage.countermeasure.capacity * 0.7)" />
Here the author calculate both of them, It seems will gain two different value.
not sure what you mean? these two initialize how many missiles and how many countermeasures a ship might want when determining if it wants to go in for supplies.
EGOiNahoo wrote:
Sat, 1. Oct 22, 12:44
--- 4. what is "macro"?
I find few description but many appears on some ingame-value change. It seems to a proxy to handler ingame-value?

Code: Select all

<evaluate_missile_storage object="this.assignedcontrolled" level="$loadoutlevel_interrupt" amounts="$output_ammoamounts_interrupt" macros="$output_ammomacros_interrupt" />
this function offer two values as amounts and macros, but for calculate number of missle needed just need `ammostorage.missile.capacity - ammostorage.{$targetcate}.count` in my opinion.
keeping in mind that this explanation is very simplified: a macro is the form in which all of the various objects in the game are defined and interface with the rest of the game. macros generally refer to a kind of item rather than a specific item of a certain type.

for example:
macro.ship_arg_s_fighter_01_a_macro refers to a Nova Vanguard (as opposed to an Elite Sentinel or a pulse laser), but it doesn't refer to a specific Nova. useful if asked "what kind of ship do you want?"

hope that makes sense. come to think of it, i've never tried to explain what a macro is before.
EGOiNahoo wrote:
Sat, 1. Oct 22, 12:44
--- 5. how the script work?

I think a whole resupply may includes 'check ammo' - 'find supply station/ship' - 'fly and dock' - 'apply supply'
File 'interrupt.restock.xmd' ending with 'clamp_equipment_amount / add_build_to_modify_ship / create_order(RestockSubordinates)'.

The command 'clamp_equipment_amount / add_build_to_modify_ship' apply game-value change directly ? or just create a interal "fly and dock and apply" order like a blackbox ?
add_build_to_modify_ship adds the Equip order to fly to a station or fleet auxiliary ship and resupply or get repairs.

EGOiNahoo
Posts: 7
Joined: Tue, 27. Sep 22, 21:00

Re: How to explain <set_value> without exact?

Post by EGOiNahoo » Sat, 1. Oct 22, 15:17

Let me try to repeat some point i'm not sure as my words.

For q1/2
I relearn Mission Director Guide just now. looks like this is a reference for latest<cue> or <libaray>. And every variable declaration is store at one cue. and it use parent namespace fisrt.
And interrupt/handler like a code fragment, so if I want to know what is `this.assignedcontrolled` , i should find somewhere run this fragment.

For q3
Maybe i'm not actually understand what is "countermeasures", I play game in other language which not English. Is it means missle counter equip like decoy ?

j.harshaw
EGOSOFT
EGOSOFT
Posts: 1868
Joined: Mon, 23. Nov 15, 18:02

Re: How to explain <set_value> without exact?

Post by j.harshaw » Sat, 1. Oct 22, 15:47

EGOiNahoo wrote:
Sat, 1. Oct 22, 15:17
For q1/2
I relearn Mission Director Guide just now. looks like this is a reference for latest<cue> or <libaray>. And every variable declaration is store at one cue. and it use parent namespace fisrt.
And interrupt/handler like a code fragment, so if I want to know what is `this.assignedcontrolled` , i should find somewhere run this fragment.
MD and AI are different, things that apply to one don't always apply to the other. The Mission Director Guide describes how MD works, not AI.

In MD, as you stated, 'this' applies to a cue, so 'this.assignedcontrolled' has no meaning.
In AI, 'this' applies to the entity executing the script. 'this.assignedcontrolled' refers to the object that 'this' is assigned to control.
EGOiNahoo wrote:
Sat, 1. Oct 22, 15:17
For q3
Maybe i'm not actually understand what is "countermeasures", I play game in other language which not English. Is it means missle counter equip like decoy ?
They're munitions which you launch to counter missiles. Which language are you playing in? In German, they're referred to in-game as "Gegenmaßnahmen".

EGOiNahoo
Posts: 7
Joined: Tue, 27. Sep 22, 21:00

Re: How to explain <set_value> without exact?

Post by EGOiNahoo » Sat, 1. Oct 22, 17:17

In chinese.
I seaching this keyworld, yes, countermeasure is decoy.

Code: Select all

<t id="915">Kaufe Gegenmaßnahmen, um die bevorstehenden Raketenangriffe abzuwehren.</t>
<t id="915">购买干扰弹防御来袭的导弹攻击。</t>

Post Reply

Return to “X4: Foundations - Scripts and Modding”