Key Names for ScenEdit_SetKeyValue

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

Key Names for ScenEdit_SetKeyValue

Post by jkgarner »

OK,

The documentation for ScenEdit_SetKeyValue reads:
ScenEdit_SetKeyValue (key,value,forCampaign)

Sets the value for a key in the persistent key store.

This function allows you to add values,associated with keys,to a persistent store KeyStore that is retained when the game is saved and resumed. Keys and values are both represented as non-nil strings.The value is retrieved by ScenEdit_GetKeyValue.
Parameters
key string The key to associate with
value string The value to associate
for Campaign boolean Pass the store to next scenario in campaign. Optional, default = false
There is no indication that either string has any limitation, however the key name string is limited to letters, numbers, hyphens and underscores. Some might say, "DUH, it's a name" but There is a bank here in the US called BB&T, whose name does not meet that criteria.

My first complaint is there is not indication that the limitation exists in the documentation.

My second is less a complaint and more a question:
why the character limitation? Does allowing a special characters in the name here actually cause issues? Perhaps the storage/retrieval mechanism imposes the limits. In this case, please, document it, so that the users are not guessing and trying various combinations. If this is not the case, can we remove the limitation?

FYI:
Characters permitted in Key Names: all letters (a-z,A-Z), numbers (1-9) and - _ .

Characters NOT permitted in Key Names: , / < > ? ; \ ' : " [ ] \ { } | ` = ~ ! @ # $ % ^ & * ( ) +

There is no limitation to characters on the Key Value string.



KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Key Names for ScenEdit_SetKeyValue

Post by KnightHawk75 »

In addition it should not start it with XML or Xml, and may include a period (.) though I don't recommend using periods, and should start with a letter or _ and not a number.

The reasoning I believe is it's following the general rules of any XML element (this is how they are stored internally), and yeah that probably should be mentioned in the docs.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Key Names for ScenEdit_SetKeyValue

Post by jkgarner »

Stating that key names must follow XML element name standards would really help.
(be considered mandatory)

For the uninitiated:

XML elements must follow these naming rules:

Element names are case-sensitive.
Element names must start with a letter or underscore.
Element names cannot start with the letters xml (or XML, or Xml, etc)
Element names can contain letters, digits, hyphens, underscores, and periods.
Element names cannot contain spaces.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Key Names for ScenEdit_SetKeyValue

Post by jkgarner »

OK,

I developed a pair of functions for removing the special characters that KeyNames (XML Elements) will not support, and replacing them with codes that allow me to undo the change with the inverse function.

RemoveSpecialChars
ReplaceSpecialChars

The functions work with a SpecialCharacter table, that lits the characters that will be removed, and gives the code that will be inserted into the string in its place in the RemoveSpecialChars function. Or conversely the codes that are searched and the characters that will be inserted, if you are calling ReplaceSpecialChars function.

I also developed test code to prove that the functions behave as expected.

I have (attempted) to upload the file to this post, if you want to take a look at the functions. Feel free to use them, if they are helpful to you.
Attachments
specialchart.txt
(8.68 KiB) Downloaded 10 times
Post Reply

Return to “Lua Legion”