Page 1 of 1

Key Names for ScenEdit_SetKeyValue

Posted: Wed Mar 10, 2021 7:51 am
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.




RE: Key Names for ScenEdit_SetKeyValue

Posted: Wed Mar 10, 2021 1:30 pm
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.

RE: Key Names for ScenEdit_SetKeyValue

Posted: Wed Mar 10, 2021 3:54 pm
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.

RE: Key Names for ScenEdit_SetKeyValue

Posted: Thu Mar 11, 2021 6:54 pm
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.