Variable Macro Name Not Working

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

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

Post Reply
user1679
Posts: 761
Joined: Fri, 20. Jul 18, 23:20

Variable Macro Name Not Working

Post by user1679 » Sun, 1. Aug 21, 01:24

Even though I use an existing macro (character_argon_female_dyn_uniform_crew_01_macro), my spawned NPC is always either AFR or ASI, never CAU even though there
are CAU features defined. Also, the macro's dynamic features aren't very dynamic. I ended up with a bunch of AFR or ASI with the same face but different hair after
spawning 100 of them across 10 M class Miner ships.

So to spawn all three, I copied the existing macro to my own 'macros' file and renamed it. I then made a second macro that always spawns a CAU and added both
of these using a DIFF/ADD operation:


arg_f_manager1_macro
arg_f_manager2_macro


The problem is that I can't get these macros to work by using a random roll to decide if it is a "1" or "2" that should be spawned. I've tried several different
ways but I get different errors:


1. These methods result in: $theMacro is not of datatype macro

Code: Select all

<set_value name="$charMacroID" exact="['1', '2'].random" />
<set_value name="$theMacro" exact="''macro.arg_f_manager' + $charMacroID + '_macro''" />
<debug_to_file name="$DebugFile" directory="$DebugDir" text="'macro generated: %s'.[$theMacro]" />
<create_npc_template name="$crewTemplate" object="$SelectedShip" macro="'$theMacro'" role="entityrole.service" force="false" /> 

Code: Select all

<set_value name="$charMacroID" exact="['1', '2'].random" />
<set_value name="$theMacro" exact="''macro.arg_f_manager[%s]_macro'.[$charMacroID]''" />
<debug_to_file name="$DebugFile" directory="$DebugDir" text="'macro generated: %s'.[$theMacro]" />
<create_npc_template name="$crewTemplate" object="$SelectedShip" macro="'$theMacro'" role="entityrole.service" force="false" /> 

2. This method results in: Cannot find macro XML file from index '$themacro' in file 'index\macros'


Code: Select all

<set_value name="$charMacroID" exact="['1', '2'].random" />
<set_value name="$theMacro" exact="'arg_f_manager' + $charMacroID + '_macro''" />
<debug_to_file name="$DebugFile" directory="$DebugDir" text="'macro generated: %s'.[$theMacro]" />
<create_npc_template name="$crewTemplate" object="$SelectedShip" macro="macro.$theMacro" role="entityrole.service" force="false" /> 


My debug log shows that appending the number to the macro name is working but it appears the result is unusable as a macro object. Is it not possible to use a random macro name
without hard coding the choices in the actual MD file? I really don't want to do this for every type of macro (pilot, manager, etc.) because I may decide to add more in the future.


Code: Select all

<set_value name="$charMacroID" exact="['1', '2'].random" />
<do_if value="$charMacroID == 1">
    <create_npc_template name="$crewTemplate" object="$SelectedShip" macro="macro.arg_f_manager1_macro" role="entityrole.service" force="false" /> 
</do_if>
<do_else>
    <create_npc_template name="$crewTemplate" object="$SelectedShip" macro="macro.arg_f_manager2_macro" role="entityrole.service" force="false" /> 
</do_else>

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

Re: Variable Macro Name Not Working

Post by kuertee » Sun, 1. Aug 21, 09:12

the actual macro reference can't be text.

this code of yours would set the var as text rather than to the macro reference:

Code: Select all

<set_value name="$theMacro" exact="''macro.arg_f_manager[%s]_macro'.[$charMacroID]''" />
i would code what you're trying to do this way:

Code: Select all

<set_value name="$theMacro" exact="[macro.arg_f_manager1_macro, macro.arg_f_manager2_macro].random" />
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.

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

Re: Variable Macro Name Not Working

Post by user1679 » Tue, 3. Aug 21, 03:54

kuertee wrote:
Sun, 1. Aug 21, 09:12
the actual macro reference can't be text.

this code of yours would set the var as text rather than to the macro reference:

Code: Select all

<set_value name="$theMacro" exact="''macro.arg_f_manager[%s]_macro'.[$charMacroID]''" />
i would code what you're trying to do this way:

Code: Select all

<set_value name="$theMacro" exact="[macro.arg_f_manager1_macro, macro.arg_f_manager2_macro].random" />
Thanks for the tip. I was hoping to avoid long code lines, I guess I could put this in a cue and call it when needed so I only need to update
one block when new factions are added to the game.

I know a cue can be signaled with a parameter but can they return values too?

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

Re: Variable Macro Name Not Working

Post by kuertee » Tue, 3. Aug 21, 06:00

there are several methods to get data back from a signal_cue_instantly.
the easiest method is:

Code: Select all

<cue name="cue_1">
<conditions>
<event_cue_signalled />
</conditions>
<actions>
<signal_cue_instantly cue="cue_2" param="table[$fromCue = namesapce]" />
<debug_text text="'$returnedValue: ' + $returnedValue" />
<reset_cue cue="this" />
</actions>
</cue>

<cue name="cue_2">
<conditions>
<event_cue_signalled />
</conditions>
<actions>
<set_value name="$fromCue" exact="event.param.$fromCue" />
<set_value name="$fromCue.$returnValue" exact=""'retruned value'" />
<reset_cue cue="this" />
</actions>
</cue>
be careful with the $fromCue var.
i used "namespace" in this example so that the $returnedValue var will be accessible anywhere within cue_1's namespace.
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.

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

Re: Variable Macro Name Not Working

Post by user1679 » Tue, 3. Aug 21, 06:28

Interesting, it's almost like a reference variable but a little more dangerous ;)

I just went with a script variable which I set in my signaled cue. Since I'm spawning an NPC, it doesn't matter if it ends up invalid because the spawn will just fail and a debug log entry gets made.

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

Re: Variable Macro Name Not Working

Post by kuertee » Tue, 3. Aug 21, 12:23

user1679 wrote:
Tue, 3. Aug 21, 06:28
Interesting, it's almost like a reference variable but a little more dangerous ;)

I just went with a script variable which I set in my signaled cue. Since I'm spawning an NPC, it doesn't matter if it ends up invalid because the spawn will just fail and a debug log entry gets made.
the only danger is confusion when trying to access a var in a different scope. coder problems. :D
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
Moonrat
Posts: 1353
Joined: Sun, 20. Apr 08, 16:20
x4

Re: Variable Macro Name Not Working

Post by Moonrat » Wed, 4. Aug 21, 21:29

I have this bit of code within my Encounters mod which formulates an explicit macro from a number of variables. I hope that helps. Useful if you've got a large number of possible macros which could be defined by a few variables.

Code: Select all

<set_value name="$EncounterObjMacro" exact="macro.{'asteroid_turret_' + $EncounterFaction.primaryrace.id + '_' + $FightRank + $SubFaction + '_macro'}"/>
[ external image ]
IEX Download Statistics - LUVi / XRMi ( 3115 / 5415 )
X4 Crexit 324 ; X4 Encounters 3193 (STEAM Unique/Current 6341/3412)

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

Re: Variable Macro Name Not Working

Post by user1679 » Fri, 6. Aug 21, 03:12

Moonrat wrote:
Wed, 4. Aug 21, 21:29
I have this bit of code within my Encounters mod which formulates an explicit macro from a number of variables. I hope that helps. Useful if you've got a large number of possible macros which could be defined by a few variables.

Code: Select all

<set_value name="$EncounterObjMacro" exact="macro.{'asteroid_turret_' + $EncounterFaction.primaryrace.id + '_' + $FightRank + $SubFaction + '_macro'}"/>
Thanks for the tip. I tried something similar in the beginning but I kept getting errors in the debug log about datatypes. Maybe I had a misplaced quote somewhere, that's
one of the downfalls of non-compiled languages without a proper IDE.

Post Reply

Return to “X4: Foundations - Scripts and Modding”