Kodi Community Forum

Full Version: setting default values for strings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In my skin edits, I created a means of the user to change some basic colors.   That works just fine.  My issue is for a fresh setup of the skin, the string values for the colors are null.

For example, from settings.xml in the userdata
<setting id="PlayerTextColor" type="string"></setting>

The side effect of this is that the text has no color (and thus not visible).   The same situation exists for textures, but they all default to the basic color of the texture (in this case white).

In some other skins I've seen stuff like this in variables.xml but it does not seem to help.

    <variable name="PlayerTextColor">
        <value condition="String.IsEmpty(Skin.String(PlayerTextColor))" />
        <value>white</value>
    </variable>

I've poked at this for a couple days, and can't seem to get past this.   Any help is appreciated.
In the startup.xml you can define the default values.

<onload condition="String.IsEmpty(Skin.String(PlayerTextColor))">Skin.SetString(PlayerTextColor,white)</onload>
afaik there's no way to set a default value for a skin string.
you would need to handle the empty string in your xml code.

a variable should do the trick, you just need to get it right (the example you've posted isn't)
    <variable name="PlayerTextColor">
        <value condition="!String.IsEmpty(Skin.String(PlayerTextColor))">$INFO[Skin.String(PlayerTextColor)]</value>
        <value>white</value>
    </variable>
(2019-02-27, 00:05)ronie Wrote: [ -> ]afaik there's no way to set a default value for a skin string.
i take that back then ;-)


edit.. or not, if you switch from skin A to skin B, it does not go through Startup.xml
so you'll have to restart Kodi once for the default values to be set.
Thanks ronnie / Hitcher.

Using defaults.xml worked perfectly.

I tried the suggestion for using a variable with the right syntax, but putting that in variables.xml did not seem to work.   I had seen something similar in the Box skin, but did not get that to work either.   Odd.   Could there be something else I have done in my files that would prevent it from working?   Just curious.
(2019-02-27, 05:58)illfigurethisout Wrote: [ -> ]I tried the suggestion for using a variable with the right syntax, but putting that in variables.xml did not seem to work.
 Did you call the variable in your label control?
Code:
<textcolor>$VAR[PlayerTextColor]</textcolor>

That works perfectly in my custom skin. And I use variables a lot – for colors, labels, textures and even onclick actions! 
But I also have a included a 'first run wizard' that gives the user the opportunity to set the most basic settings for the skin when it is started for the first time (an onload in home.xml checks if a specific string is empty, and when it is empty a custom dialog window with the setting options is called).
(2019-02-27, 05:58)illfigurethisout Wrote: [ -> ] Did you call the variable in your label control?
 The honest answer is - not anymore.  It's set up like this now -
    <textcolor>$INFO[Skin.String(PlayerTextColor)]</textcolor>

While I was modifying/creating the xml for choosing colors, the colors stopped showing up in the skin.   After fiddling with it for a while, I got it working again by using $INFO.    I'm sure I broke something on the choosing side of things and $INFO is just a band aid to make it work again. FWIW, this is the line that assigns the color. 
<onclick>Skin.SetString($VAR[SetColor],Color11)</onclick>
A prior window assigns a value to the string SetColor when the user chooses which color to set from this
<onclick>Skin.SetString(ChangeSkinColor,3)</onclick>
Which then pulls from variables.xml -
<variable name="SetColor">    
    <value condition="Skin.String(ChangeSkinColor,3)">PlayerTextColor</value>   
 </variable>
I'm happy that it works, but it seems that I hacked it up a bit to get it functioning.
I think what you need is a variable which returns the colors to be used based on a string you defined.



<variable name="SkinTextColor">
<value condition=Skin.String(UserSelectedColor,1)>Red</value>
<value condition=Skin.String(UserSelectedColor,2)>Blue</value>
...
<value>white</value>
</variable>


Then you could have a color picker, which sets the value of the Skin.String and thus ultimately sets color via the defined variable.

Something like:



<control type = "panel">
<itemlayout>
....
</itemlayout>
<focusedlayout>
......
</focusedlayout>
<content>
<item id=1>
.....


<onclick>Skin.SetString(UserSelectedColor, 1)</onclick>
</item>
<item id=2>
....

<onclick>Skin.SetString(UserSelectedColor, 2)</onclick>
</item>
........
</content>
</control>


then simply use the variable to use the color


<textcolor>$VAR[SkinTextColor]</textcolor>

p.s. With regard to your comment on the usage of $INFO, this is not a hack, you have to use it. With this you say that you want the String stored returned. If you do not use $INFO then you are not asking for the actual String, you are asking wether or not the String is empty, so get a boolean value as a result.
@DjCisco 
Your code could be reduced! When the color picker looks like this

<control type = "panel">
<itemlayout>
....
</itemlayout>
<focusedlayout>
......
</focusedlayout>
<content>
<item id=1>
.....


<onclick>Skin.SetString(UserSelectedColor, Red)</onclick>
</item>
<item id=2>
....

<onclick>Skin.SetString(UserSelectedColor, Blue)</onclick>
</item>
........
</content>
</control>

(where 'Red', 'Blue' are the color names defined in /colors/defaults.xml), then the Variable needs only one condition:
<variable name="SkinTextColor">
   <value condition="!String.IsEmpty(Skin.String(UserSelectedColor))">$INFO[Skin.String(UserSelectedColor)]</value>
   <value>white</value>
</variable>
(2019-02-28, 12:49)JackTirol Wrote: [ -> ]@DjCisco 
Your code could be reduced! When the color picker looks like this

<control type = "panel">
<itemlayout>
....
</itemlayout>
<focusedlayout>
......
</focusedlayout>
<content>
<item id=1>
.....


<onclick>Skin.SetString(UserSelectedColor, Red)</onclick>
</item>
<item id=2>
....

<onclick>Skin.SetString(UserSelectedColor, Blue)</onclick>
</item>
........
</content>
</control>

(where 'Red', 'Blue' are the color names defined in /colors/defaults.xml), then the Variable needs only one condition:
<variable name="SkinTextColor">
   <value condition="!String.IsEmpty(Skin.String(UserSelectedColor))">$INFO[Skin.String(UserSelectedColor)]</value>
   <value>white</value>
</variable>
 Ahh yes, nice!!!!!
@JackTirol 

My Color picker looks pretty much like your example, but interestingly I don't have this piece -

(where 'Red', 'Blue' are the color names defined in /colors/defaults.xml), then the Variable needs only one condition:
<variable name="SkinTextColor"> <value condition="!String.IsEmpty(Skin.String(UserSelectedColor))">$INFO[Skin.String(UserSelectedColor)]</value> <value>white</value> </variable>

It's been mentioned here that is used for setting, for lack of a better term, a default value for color.    Although I can't seem to get it to work that way, does this xml serve any other purpose?  Otherwise, I seem to be getting along without it for now.
(2019-02-28, 16:17)illfigurethisout Wrote: [ -> ]It's been mentioned here that is used for setting, for lack of a better term, a default value for color.    Although I can't seem to get it to work that way, does this xml serve any other purpose?  Otherwise, I seem to be getting along without it for now.
 To me it's not really clear which problem you have with it. But I'll try to explain it (see the comments in the code block). 

In variables.xml:
<variable name="SkinTextColor">
   <value condition="!String.IsEmpty(Skin.String(UserSelectedColor))">$INFO[Skin.String(UserSelectedColor)]</value>  <!-- This checks if the string is empty. If not, the INFO will get the value (color) defined in the picker -->
   <value>white</value>  <!-- This is the default color if the color isn't yet set by the user (string is empty) -->
</variable>

In your controls you have to call the color like mentioned several times before in this thread:
<textcolor>$VAR[SkinTextColor]</textcolor>

Hope this makes the whole stuff a bit clearer ...  Smile
I have no problem understanding.   This issue was on execution.   I had a stray ) where a ] should have been in variables.xml

All is well now.   

Thanks.
maybe that helps too.

start up xml
call the include as onload action
e.g.
<include condition="!Skin.HasSetting(StartupDefaults)">SetDefaultSkinSettings</include>


set defaults / define it
some examples

<include name="SetDefaultSkinSettings">
<!-- Set strings -->
   <onload condition="!Skin.String(foobar_skinstring)">Skin.SetString(foobar_skinstring, foobavralue)</onload>
   <onload condition="!Skin.String(foobarcolor.color)">Skin.SetString(foobarcolor, colorhex)</onload>
<!--eg
<onload condition="!Skin.String(foobarcolor.Color)">Skin.SetString(foobarcolor.Color,ffffffff)</onload>
<onload condition="!Skin.String(foobarcolor.Color.name)">Skin.SetStringfoobarcolor.Color.name,white)</onload>
 -->
.
.
<!-- Set Bools --> 
<onload>Skin.SetBool(foobarskinsettingbool)</onload>
.
.
<!-- Set Defaults to true, for next load -->
<onload>Skin.SetBool(StartupDefaults)</onload>
</include>
(2019-02-27, 00:05)ronie Wrote: [ -> ]
(2019-02-27, 00:05)ronie Wrote: [ -> ]afaik there's no way to set a default value for a skin string.
i take that back then ;-)


edit.. or not, if you switch from skin A to skin B, it does not go through Startup.xml
so you'll have to restart Kodi once for the default values to be set.

@ronie (and everyone else) - FYI - you can get around this issue by using an <onunload> in DialogConfirm.xml to force Startup.xml
Confirm dialog is always launched when switching skins.

DialogConfirm:
Code:
<onunload condition="String.IsEmpty(Window(Home).Property(SkinInitStarted))">ReplaceWindow(Startup.xml)</onunload>

Startup:
Code:
<onload condition="String.IsEmpty(Skin.String(MyString))>Skin.SetString(MyString,Value)</onload>
<onload>SetProperty(SkinInitStarted,1,Home)</onload>