Problem understanding namespace

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

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

Teladidrone
Posts: 644
Joined: Tue, 24. Aug 04, 11:41
x3tc

Problem understanding namespace

Post by Teladidrone » Mon, 15. Jan 24, 18:18

Trying to teach myself md scripting and for a starting point I used the mod Player jump v0.5.

So far so good, I do think I understand the md code except for one thing:
I do not get how/why sometimes namespace="this" is added in a cue definition and sometimes not. I tried to look up more about namespaces in the wiki but there I only found information about it and why/when it might be needed if sub cues or library cues are involved.

The simple example here does declare several cues, but they are all on the same level? No sub cues, no libraries.
The cues communicate/sync with each other using two global variables, they never read each others variables? Still, why is this needed sometimes and sometimes not and what does it do here? I am really confused, someone please enlighten me..

For easy reference, this is the full example code:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<mdscript name="EuclidsAnomalyGeneratorGuidance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
 <cues>
	 
	 <cue name="EuclidsAnomalyGeneratorTrigger" instantiate="true" namespace="this">
			<conditions>
			 <event_object_signalled object="player.entity" param="'set guidance'" />
			 <!-- does player hsip exists, is it not docked, is he not just standing in the ship, is it his ship -->
			 <check_value value="player.ship and player.ship.parent.isclass.zone and player.occupiedship and player.ship.isplayerowned"/>  
    </conditions>
		<actions>
			<do_if value="@event.param2.{1}">
              <set_value name="global.$EuclidsTarget" exact="event.param2.{1}"/>
			  <set_value name="global.$EuclidsPosition" exact="position.[0,0,0]"/>	
			  <do_if value="not event.param2.{1}.isclass.zone">
			    <set_value name="global.$EuclidsTarget" exact="event.param2.{1}.zone"/>
				<set_value name="global.$EuclidsPosition" exact="event.param2.{1}.position"/> 
			  </do_if>
			  <do_if value="@event.param2.{2}">
				<set_value name="global.$EuclidsPosition" exact="event.param2.{2}"/>	
			  </do_if>
			  <set_value name="global.$EuclidsJumpOrNotJump" exact="true"/>	
		    </do_if>	
		</actions>
	 </cue>
	 
	  <cue name="EuclidsAGInit" instantiate="true" >
		<conditions>
			<event_ui_triggered screen="'MapMenu'" control="'menu_close'"/>	
		</conditions>
    <actions>
			<do_if value="global.$EuclidsJumpOrNotJump?">
				<start_conversation actor="player.computer" conversation="EuclidsAnomalyGeneratorMenu" type="unqueued" />
		    </do_if>
		</actions>
	 </cue>
	 
	 <cue name="EuclidsAG" instantiate="true" >
		<conditions>
			<event_conversation_started conversation="EuclidsAnomalyGeneratorMenu" /> 
		</conditions>
    <actions>
			<add_player_choice text="'Jump to Guidance?'" section="gjump"/>
			<add_player_choice text="'No Thanks'" section="nothanks"/> 
		 </actions>
	 </cue>
	 
	 
	 <cue name="EuclidsAGConvInit1" instantiate="true" namespace="this">
		 <conditions>
			<event_conversation_next_section sectionprefix="gjump"/>
		 </conditions>
     <delay exact="1s"  />
		 <actions>
			 <do_if value="event.param == 'gjump'">
				 <speak actor="player.computer" line="506" comment="Anomaly detected" /> 
				 <force_player_speed speed="0"/>
			   <signal_cue cue="EuclidsAGConvInit"/>
			 </do_if>
		 </actions>
	 </cue>
	 
	 <cue name="EuclidsAGConvEnd" instantiate="true">
		 <conditions>
			<event_conversation_next_section sectionprefix="nothanks"/>
		 </conditions>
		 <actions>
			<reset_cue cue="EuclidsAnomalyGeneratorTrigger"/>
			<cancel_conversation actor="player.computer" />
			<remove_value name="global.$EuclidsJumpOrNotJump"/>   
		 </actions>
	 </cue>	
	 
	 <cue name="EuclidsAGConvInit" instantiate="true" namespace="this">
		 <conditions>
			<event_cue_signalled />
		 </conditions>
     <delay exact="3s"  />
		 <actions>
			<add_effect object="player.ship" effect="'hq_warpin'">
              <safepos value="player.ship.position"/>
            </add_effect>
		   <signal_cue cue="EuclidsAGConvNow"/>
		 </actions>
	 </cue>
	 
	 <cue name="EuclidsAGConvNow" instantiate="true" namespace="this">
		 <conditions>
			<event_cue_signalled />
		 </conditions>
     <delay exact="3s"  />
		 <actions>
			<warp object="player.ship" zone="global.$EuclidsTarget" >
              <safepos value="global.$EuclidsPosition"/>
            </warp>
			<remove_value name="global.$EuclidsJumpOrNotJump"/> 
		</actions>
	 </cue>
	 	 
 </cues>
</mdscript>


kuertee
EGOSOFT
EGOSOFT
Posts: 789
Joined: Sun, 14. Dec 03, 13:05
x4

Re: Problem understanding namespace

Post by kuertee » Tue, 16. Jan 24, 05:34

I don't think it's required in that example.

In its most basic use, namespace = scope of variables.
i.e.: namespace=this means that variables within that cue are localised within that cue. And that cue's access to variables outside it will need to be prefixed with those variables' namespace. Other cue's access to variables within that cue will also need to be prefixed with that cue's namespace.

This code example may contain errors. It's just a sample.

Code: Select all

<cue name="MainCue">
  <actions>
    <set_value name="$Foo" exact="'abc'" />
  </actions>
  <cues>
    <cue name="SubCue" namespace="this">
      <actions>
        <debug_text text="'$Foo: ' + $Foo" comment="will log an error as $Foo is inaccessible" />
        <debug_text text="'parent.$Foo: ' + parent.$Foo" comment="will log 'abc'" />
        <debug_text text="'MainCue.$Foo: ' + MainCue.$Foo" comment="will log 'abc'" />

        <set_value name="$Bar" exact="'123'" />
      </actions>
    </cue>
    <cue name="SubCue2">
      <actions>
        <debug_text text="'$Foo: ' + $Foo" comment="will log 'abc'" />
        <debug_text text="'parent.$Foo: ' + parent.$Foo" comment="will log 'abc'" />
        <debug_text text="'MainCue.$Foo: ' + MainCue.$Foo" comment="will log 'abc'" />

        <debug_text text="'$Bar: ' + $Bar" comment="will log an error as $Bar is inaccessible" />
        <debug_text text="'SubCue.$Bar: ' + SubCue.$Bar" comment="will log '123'" />
      </actions>
    </cue>
  </cues>
</cue>
Mods: RPG: Reputations and Professions, Social Standings and Citizenships, Crime has Consequences, Alternatives to Death. Missions/NPCs: Emergent Missions, NPC Reactions, Mod Parts Trader, High-sec Rooms are Locked, Hacking Outcomes, More Generic Missions, Waypoint Fields for Deployment. Others: Auto-cam, Friendly Fire Tweaks, Teleport From Transporter Room, Wear and Tear. QoL: Trade Analytics, Loot Mining, Ship Scanner, Signal Leak Hunter, Station Scanner, Surface Element Targeting, etc.

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13308
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Problem understanding namespace

Post by euclid » Tue, 16. Jan 24, 14:59

In addition to what kuertee wrote:

The only alternative to "this" would be "static" which makes only sense (and hence a difference) if that cue is instantiated, i.e. " ... instantiate="true" namespace="static"> ... ". And, ofc, kuertee is right that in that cue from PlayerJump the namespace is not necessary but it doesn't hurt to have it there ;-)

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

Teladidrone
Posts: 644
Joined: Tue, 24. Aug 04, 11:41
x3tc

Re: Problem understanding namespace

Post by Teladidrone » Tue, 16. Jan 24, 20:44

Ty all for explaining!

Return to “X4: Foundations - Scripts and Modding”