write_to_logbook doesn't accept variable for category

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

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

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

write_to_logbook doesn't accept variable for category

Post by user1679 » Tue, 12. Jul 22, 05:03

I was trying to write a logger library and I noticed that write_to_logbook generates an "invalid category" error if you try to use a variable.
The strange thing is the other parameters accept variables.

The category field is listed as a "logcategorylookup" which is of type string:
Spoiler
Show

Code: Select all

<xs:element name="write_to_logbook">
        <xs:annotation>
          <xs:documentation>
            Write an entry into the logbook
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:attributeGroup ref="action" />
          <xs:attribute name="category" type="logcategorylookup" use="required" />
          
  <xs:simpleType name="logcategorylookup">
    <xs:annotation>
      <xs:documentation>
        Logbook category
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="general" />
      <xs:enumeration value="missions" />
      <xs:enumeration value="news" />
      <xs:enumeration value="upkeep" />
      <xs:enumeration value="alerts" />
      <xs:enumeration value="tips" />
    </xs:restriction>
  </xs:simpleType>
In my logger I have a parameter:

<param name="logbookCategory" default="upkeep" />

But this fails:

<write_to_logbook category="$logbookCategory"
<write_to_logbook category="'%s'.[$logbookCategory]"

and changing the param to include the single quotes also fails:

<param name="logbookCategory" default="'upkeep'" />

The only way I could get it to work is to use the literal string and supply variables for the remaining parameters:

<write_to_logbook category="upkeep" title="$logbookTitle" message="$logMsg" />

DeadAirRT
Posts: 1020
Joined: Fri, 25. Jan 19, 03:26
x4

Re: write_to_logbook doesn't accept variable for category

Post by DeadAirRT » Tue, 12. Jul 22, 05:31

I'm surprised that set_value "'upkeep'" (shorthand because phone) didn't work but at least the workaround is extremely simple.

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

Re: write_to_logbook doesn't accept variable for category

Post by user1679 » Tue, 12. Jul 22, 08:43

DeadAirRT wrote:
Tue, 12. Jul 22, 05:31
I'm surprised that set_value "'upkeep'" (shorthand because phone) didn't work but at least the workaround is extremely simple.
Yeah, I tried all variations to force that parameter to take a variable but since it won't, I just used a few "do_elseif" statements.
Thankfully there aren't a lot of options for "category".

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

Re: write_to_logbook doesn't accept variable for category

Post by euclid » Tue, 12. Jul 22, 13:21

Shot in the dark: <param name="logbookCategory" value="upkeep" />

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

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

Re: write_to_logbook doesn't accept variable for category

Post by user1679 » Wed, 13. Jul 22, 03:05

euclid wrote:
Tue, 12. Jul 22, 13:21
Shot in the dark: <param name="logbookCategory" value="upkeep" />

Cheers Euclid
Thanks but to provide a value for a library parameter, you have to use the default keyword. Using this makes the parameter
optional because it will use that default value if none is passed.

None of this works, except the last one with the hard-coded category:

Code: Select all

<library name="SomeLibrary" purpose="run_actions" version="100">
    <params>
        <param name="logbookCategory" default="upkeep" />
        <param name="logbookCategory2" default="'upkeep'" /> <!-- added single quotes around upkeep -->
        <param name="logbookTitle" />
        <param name="logbookText" />
    </params>
    <actions>
    
        <!-- Use $ to refer to the parameter because the library automatically generates a variable. You can't use $ in the parameter itself, invalid. -->
        
        <write_to_logbook category="$logbookCategory" title="$logbookTitle" text="$logbookText" /> <!-- missing or invalid category -->
        <write_to_logbook category="'%s'.[$logbookCategory]" title="$logbookTitle" text="$logbookText" /> <!-- missing or invalid category -->
        <write_to_logbook category="logbookCategory" title="$logbookTitle" text="$logbookText" /> <!-- logbookCategory is undeclared, causes error -->
        
        <write_to_logbook category="$logbookCategory2" title="$logbookTitle" text="$logbookText" /> <!-- missing or invalid category -->
        <write_to_logbook category="'%s'.[$logbookCategory2]" title="$logbookTitle" text="$logbookText" /> <!-- missing or invalid category -->
        <write_to_logbook category="logbookCategory2" title="$logbookTitle" text="$logbookText" /> <!-- logbookCategory2 is undeclared, causes error -->
        
        <write_to_logbook category="upkeep" title="$logbookTitle" text="$logbookText" /> <!-- Thanks for supplying a category!!!! -->
    </actions>
</library>

DeadAirRT
Posts: 1020
Joined: Fri, 25. Jan 19, 03:26
x4

Re: write_to_logbook doesn't accept variable for category

Post by DeadAirRT » Wed, 13. Jul 22, 05:54

I wonder if it would work similar to commandaction

Set_value name="$cat" exact="logbookcategory.upkeep"

I really doubt it though

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

Re: write_to_logbook doesn't accept variable for category

Post by user1679 » Wed, 13. Jul 22, 09:10

DeadAirRT wrote:
Wed, 13. Jul 22, 05:54
I wonder if it would work similar to commandaction

Set_value name="$cat" exact="logbookcategory.upkeep"

I really doubt it though
No, that doesn't work either. I tried:

<param name="logCat" default="logbookcategory.upkeep" />
<write_to_logbook category="$logCat" ... />

but still got the "invalid or missing category" error. It's strange that this is the only thing the XML interpreter seems to have
a problem with. All other parameters in this method can be passed as literals or variables.

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

Re: write_to_logbook doesn't accept variable for category

Post by euclid » Wed, 13. Jul 22, 13:02

user1679 wrote:
Wed, 13. Jul 22, 03:05
euclid wrote:
Tue, 12. Jul 22, 13:21
Shot in the dark: <param name="logbookCategory" value="upkeep" />

Cheers Euclid
Thanks but to provide a value for a library parameter, you have to use the default keyword. Using this makes the parameter
optional because it will use that default value if none is passed.....
Likely I'm missing something here but what I meant is to use <param name="logbookCategory" /> within your lib and then the above when the lib is called via run_actions.

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

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

Re: write_to_logbook doesn't accept variable for category

Post by user1679 » Thu, 14. Jul 22, 02:54

euclid wrote:
Wed, 13. Jul 22, 13:02
user1679 wrote:
Wed, 13. Jul 22, 03:05
euclid wrote:
Tue, 12. Jul 22, 13:21
Shot in the dark: <param name="logbookCategory" value="upkeep" />

Cheers Euclid
Thanks but to provide a value for a library parameter, you have to use the default keyword. Using this makes the parameter
optional because it will use that default value if none is passed.....
Likely I'm missing something here but what I meant is to use <param name="logbookCategory" /> within your lib and then the above when the lib is called via run_actions.

Cheers Euclid
Oh, yeah, I tried reassignment but it also failed. But that kinda defeats the purpose of a parameter anyway, I ended up just using a bunch of do_if statements
to test the value which would be needed for reassignment too.

Post Reply

Return to “X4: Foundations - Scripts and Modding”