General problems when getting started with scripting

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

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

Post Reply
User avatar
Reisser
Posts: 745
Joined: Mon, 28. Feb 05, 15:39
x4

General problems when getting started with scripting

Post by Reisser » Sat, 11. Jun 22, 13:43

I've been struggling through my first script (or I adapt an older one for myself) for a few days now. The whole thing works halfway, but it's still really ugly.

Now I have the problem that I want to use my own library. But that doesn't work at all. It doesn't matter where I place it - it seems to be completely ignored or the rest of the script doesn't start at all.

Funnily enough, another library does it...

Although I have kept the library VERY short - basically just the framework with a <show_help> to see if it is running.

Code: Select all

	
<library name="Debug" purpose="run_actions">
	<params>
		<param name="txt" />
	</params>
	<actions>	
		<show_help custom="'DebugLog'" duration="5" log="false" position="8" allowclose="true"/> 
		<debug_to_file directory="'RS_Loss_Report'" name="'RS_Loss_Report.log'" output="false" append="true" text="'[' + player.systemtime.{'%F - %X'}.{'%F - %X'} + '] ' + $txt"/>							
	</actions>
</library>	
The call accordingly - since I also have a debug_to_file in the same place, the script should also run here

Code: Select all

<run_actions ref="Debug"> <param name="txt" value="'Testtext'" /></run_actions>
I added them to the config cue (which is definitely executed when the script is reinstalled) - no success (after the last </actions> call.

It should be said that I still have my problems with the cues - how / when / which one is called, the namespace of the variables etc ... X4 really doesn't make it easy for you

I created a custom cue for it - no success



I put them under every other cue (after </actions>) - no success

/refeshmd doesn't always seem to take over everything, and every time reloading the script via restart game took me hours and I'm about to throw away the whole crap so I can play again :o

I'm attaching the script here (it's gotten a bit longer over time and unfortunately it's really ugly code) - maybe someone can tell me how to put a library in there ... heaven! That can not be that hard!
Spoiler
Show

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<mdscript name="RS_Loss_Report" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="md.xsd">
	<cues>
	
		<cues name="Libs">
			<library name="SetWatchlist" purpose="run_actions">
				<params>
					<param name="T1" />
					<param name="T2" />
					<param name="T3" />
				</params>
				<actions>				
					<remove_value name="$Watchlist"/>
					<create_list name="$Watchlist"/>					
					<do_if value="$T1 == 1">	
						<append_list_elements name="$Watchlist" other="[class.ship_m, class.ship_l, class.ship_xl, class.station]"/>								
					</do_if>
					<do_if value="$T2 == 1">	
						<append_list_elements name="$Watchlist" other="[class.ship, class.ship_xs, class.ship_s]"/>							
					</do_if>
					<do_if value="$T3 == 1">	
						<append_list_elements name="$Watchlist" other="[class.navbeacon, class.satellite, class.turret, class.resourceprobe]"/>
					</do_if>
					<set_value name="global.$RS_Loss_Report.$Watchlist" exact="$Watchlist"/>
					<return value="$Watchlist" />								
				</actions>
			</library>	
			
			<library name="Debug" purpose="run_actions">
				<params>
					<param name="txt" />
				</params>
				<actions>	
					<show_help custom="'DebugLog'" duration="5" log="false" position="8" allowclose="true"/> 
					<debug_to_file directory="'RS_Loss_Report'" name="'RS_Loss_Report.log'" output="false" append="true" text="'[' + player.systemtime.{'%F - %X'}.{'%F - %X'} + '] ' + $txt"/>				
				</actions>
			</library>			

		</cues>

		<cue name="Init" instantiate="false">	
			<actions>
			    <debug_to_file name="'RS_Loss_Report.log'" directory="'RS_Loss_Report'" text=" player.systemtime.{'%F - %X'} + ' Start ############'" output="true" append="true" />				
						
				<!-- Grundeinstellung: Default-Wert auf "true" stellen -->							
			    <set_value name="$version" exact="0.5"/>
				<do_if value="(not global.$RS_Loss_Report.$Init?)">		
					<set_value name="global.$RS_Loss_Report" 	exact="this" />		
					<!--<set_value name="global.$RS_Loss_Report.$Watchlist" exact="table[class.ship_m,class.ship_l,class.ship_xl,class.station,class.ship,class.ship_xs,class.ship_s]" />-->
					<set_value name="$Init" 					exact="true" />
					<set_value name="$Message" 					exact="true" />
					<set_value name="$Mail"    					exact="true" />					
					<set_value name="$Debug"   					exact="false" />
					<set_value name="$Type1"   					exact="true" />
					<set_value name="$Type2"   					exact="true" />
					<set_value name="$Type3"   					exact="false" />	
					<set_value name="$Position"   				exact="7" />	
					<set_value name="$Duration"   				exact="10" />
					<run_actions ref="SetWatchlist" result="$Watchlist"><param name="T1" value="$Type1" /><param name="T2" value="$Type2" /><param name="T3" value="$Type3" /></run_actions>
					<show_help custom="'RS Loss Report ' + $Version + ' ' + {500600,150}" duration="5s"/>	
				</do_if>							
			</actions>
			

			
			<cues>
				<!-- Konigurationsmenü erstellen -->
				<cue name="Register_Options_Menu" instantiate="true">
					<conditions>
						<event_cue_signalled cue="md.Simple_Menu_API.Reloaded"/>
					</conditions>
					<actions>
						<signal_cue_instantly cue="md.Simple_Menu_API.Register_Options_Menu" param="table[$id = 'report_options_menu', $columns = 8, $title = {500600,100}, $onOpen = Main_Menu ]"/>
					</actions>
				</cue>
				<!-- Konfigurations-Untermenü erstellen -->
				<cue name="Main_Menu" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
					
						<debug_to_file name="'RS_Loss_Report.log'" directory="'RS_Loss_Report'" output="false" append="true" 
						text=" player.systemtime.{'%F - %X'} + ' Optionmenü: ' + global.$RS_Loss_Report_Config.$Init" />				

						<!-- Mail on/off -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[$col = 1,$colSpan = 6,$text = {500600,103}]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Button" param="table[
								$col = 7, 
								$colSpan = 2,
								$text = table[
								  $text   =  if $Mail == true then {500600,160} else {500600,161}, 
								  $color  = 'Helper.color.green',
								  $halign = 'center',
								],
								$onClick = Mail,
								$onRightClick = Mail,
							]"/>								
						<!-- Message on/off -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[$col = 1,$colSpan = 6,$text = {500600,102}]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Button" param="table[
								$col = 7, 
								$colSpan = 2,
								$text = table[
								  $text   =  if $Message == true then {500600,160} else {500600,161}, 
								  $color  = 'Helper.color.green',
								  $halign = 'center',
								],
								$onClick = Message,
								$onRightClick = Message,
							]"/>
						<!-- Anzeigeort auf Bildschirm -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[
								$col=1,
								$colSpan=2,
								$mouseOverText= {500600,113},
								$text = {500600,112},
								]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Slider" param="table[
								$col=7,
								$colSpan=2,
								$onSliderCellConfirm=MessagePosition,
								$min=0,
								$minSelect=0,
								$max=10,
								$maxSelect=10,
								$exceedMaxValue=false,
								$start=$Position,
								$step=1,
								$suffix='',								
								]"/>															
						<!-- Anzeigedauer auf Bildschirm -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[
								$col=1,
								$colSpan=2,
								$text = {500600,114},
								]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Slider" param="table[
								$col=7,
								$colSpan=2,
								$onSliderCellConfirm=MessageDuration,
								$min=5,
								$minSelect=5,
								$max=60,
								$maxSelect=60,
								$exceedMaxValue=false,
								$start=$Duration,
								$step=1,
								$suffix='sec',								
								]"/>	
						
						<!-- Schiffe (M,L,XL) und Stationen -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[$col = 1,$colSpan = 6,$text = {500600,106}]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Button" param="table[
								$col = 7, 
								$colSpan = 2,
								$text = table[
								  $text   =  if $Type1 == true then {500600,160} else {500600,161}, 
								  $color  = 'Helper.color.green',
								  $halign = 'center',
								],
								$onClick = Type1,
								$onRightClick = Type1,
							]"/>	
						<!-- Schiffe (XS,S) -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[$col = 1,$colSpan = 6,$text = {500600,108}]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Button" param="table[
								$col = 7, 
								$colSpan = 2,
								$text = table[
								  $text   =  if $Type2 == true then {500600,160} else {500600,161}, 
								  $color  = 'Helper.color.green',
								  $halign = 'center',
								],
								$onClick = Type2,
								$onRightClick = Type2,
							]"/>	
						<!-- Aufstellbares (Satelliten,Sonden,Verteidigungstürme -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[$col = 1,$colSpan = 6,$text = {500600,110}]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Button" param="table[
								$col = 7, 
								$colSpan = 2,
								$text = table[
								  $text   =  if $Type3 == true then {500600,160} else {500600,161}, 
								  $color  = 'Helper.color.green',
								  $halign = 'center',
								],
								$onClick = Type3,
								$onRightClick = Type3,
							]"/>	
					
						<!-- Debug on/off -->
						<signal_cue_instantly cue="md.Simple_Menu_API.Add_Row"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Text" param="table[$col = 1,$colSpan = 6,$text = {500600,104}]"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Make_Button" param="table[
								$col = 7, 
								$colSpan = 2,
								$text = table[
								  $text   =  if $Debug == true then {500600,160} else {500600,161}, 
								  $color  = 'Helper.color.red',
								  $halign = 'center',
								],
								$onClick = Debug,
								$onRightClick = Debug,
							]"/>								
					</actions>
				</cue>
			
				<cue name="MessagePosition" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Position" exact="event.param.$value"/>
					</actions>
				</cue>	
				<cue name="MessageDuration" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Duration" exact="event.param.$value"/>
					</actions>
				</cue>	
				<cue name="Message" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Message" exact="if $Message == true then false else true"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Refresh_Menu"/>
					</actions>
				</cue>
				<cue name="Mail" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Mail" exact="if $Mail == true then false else true"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Refresh_Menu"/>
					</actions>
				</cue>
				<cue name="Type1" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Type1" exact="if $Type1 == true then false else true"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Refresh_Menu"/>
						<run_actions ref="SetWatchlist" result="$Watchlist"><param name="T1" value="$Type1" /><param name="T2" value="$Type2" /><param name="T3" value="$Type3" /></run_actions>
					</actions>
				</cue>	
				<cue name="Type2" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Type2" exact="if $Type2 == true then false else true"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Refresh_Menu"/>
						<run_actions ref="SetWatchlist" result="$Watchlist"><param name="T1" value="$Type1" /><param name="T2" value="$Type2" /><param name="T3" value="$Type3" /></run_actions>
					</actions>
				</cue>	
				<cue name="Type3" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Type3" exact="if $Type3 == true then false else true"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Refresh_Menu"/>
						<run_actions ref="SetWatchlist" result="$Watchlist"><param name="T1" value="$Type1" /><param name="T2" value="$Type2" /><param name="T3" value="$Type3" /></run_actions>
					</actions>
				</cue>									
				<cue name="Debug" instantiate="true">
					<conditions>
						<event_cue_signalled/>
					</conditions>
					<actions>
						<set_value name="$Debug" exact="if $Debug == true then false else true"/>
						<signal_cue_instantly cue="md.Simple_Menu_API.Refresh_Menu"/>
					</actions>
				</cue>					
			</cues>
		</cue>
		
		
			
		<cue name="LossReport" instantiate="true">
			
			<conditions>
				<check_all>
					<event_player_owned_destroyed/>		 
					<check_object object="event.object" shiptype="shiptype.smalldrone" negate="true"/>
					<!-- <check_value value="event.param.class" list="[class.ship, class.ship_xs, class.ship_s, class.ship_m, class.ship_l, class.ship_xl, class.station]"/> -->
					<check_value value="event.param.class" list="global.$RS_Loss_Report.$Watchlist"/> -->
				</check_all>
			</conditions>
			<actions>
			
				<!-- <run_actions ref="DebugLog"><param name="txt" value="'test'" /></run_actions> -->

				<debug_to_file name="'RS_Loss_Report.log'" directory="'RS_Loss_Report'" output="true" append="true"  
							text=" player.systemtime.{'%F - %X'} + ' Watchlist unter LossReport: ' + global.$RS_Loss_Report.$Watchlist + ' Message: ' + global.$RS_Loss_Report.$Message + ' Mail: ' + global.$RS_Loss_Report.$Mail + ' Debug: ' + global.$RS_Loss_Report.$Debug" />				
			
				<set_value name="$KilledObject" exact="event.param"/>
				<set_value name="$KillerObject" exact="event.param2"/>
				<set_value name="$KillMethod" exact="event.param3"/>
		
				<do_if value="$KillMethod != killmethod.removed and $KillMethod != killmethod.collected and $KilledObject != player.controlled">
				
					<do_if value="global.$RS_Loss_Report.$Message == true">			
						<show_help custom="'\033#FFFF0000#' + {500600, 200} + '\033X' + '\n' +
									event.param.knownname + '(' + event.param.idcode + ')' + '\n' +
									{500600,202} + event.param2.sector.knownname + '\n' +
									{500600,204} + $KillerObject.knownname"
									duration="global.$RS_Loss_Report.$Duration" log="false" position="global.$RS_Loss_Report.$Position" allowclose="true"/>																		
					</do_if>
					<do_if value="global.$RS_Loss_Report.$Mail == true">			
						<write_to_logbook 	title="'\033#FFFF0000#' + {500600, 200} + '\033X'" 
											text="event.param.knownname + '(' + event.param.idcode + ')' + '\n' +
											{500600,202} + event.param2.sector.knownname + '\n' +
											{500600,204} + $KillerObject.knownname" 
											category="alerts"/>
					</do_if>														
				</do_if>		
					
				<remove_value name="$KillMethod"/>
				<remove_value name="$KillerObject"/>
				<remove_value name="$KilledObject"/>
				
		  </actions>
			
		</cue>			
		
	</cues>
</mdscript>

In the script aboveI have packed the lib to the (working) lib at the top, far below is the call. However, the whole script (except for the config menu) no longer runs ... the problem is precisely this library (the script runs without the call)

I would be super grateful if someone could give me a few tips here so I don't pull ALL my hair out here and maybe find some fun in it. Right now it's actually just frustrating and time consuming
Meine Mods bei NexusMods: RS Loss Report RS Bribe for Scandata RS Colors RS Marine Special Training
Meine Mod-Collection bei NexusMods: X4 VRO Reloaded

user1679
Posts: 789
Joined: Fri, 20. Jul 18, 23:20

Re: General problems when getting started with scripting

Post by user1679 » Mon, 27. Jun 22, 04:18

Are you starting the game in debug mode? You won't get any output from debug_to_file unless you use -logdebug when you launch the game.

Post Reply

Return to “X4: Foundations - Scripts and Modding”