[IIF] Using Conditional Statements

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Dom DXecutioner Offline
Member
Posts: 89
Joined: Jan 2010
Reputation: 0
Location: USA
Post: #1
Hello,

I have often wonder if XBMC would ever implement conditional statements. If a condition is met, return something, else return something else

PHP Code:
IIF(ConditionTest,True,False

I find it a bit cumbersome to create multiple controls to display/obtain the same info just formatted diffently.

For example, a concatinated string that may be a bit different depending on the content or lackthereof. Suppose that I want to display the year, the title... i would use and have seen the following:
PHP Code:
<control type="label">
     <
label>$INFO[ListItem.Year] | $INFO[ListItem.Title]</label>
     <
visible>!IsEmpty($INFO[ListItem.Year])</visible>
</
control
So, the control above will be visible only if the year value is not empty since I don't want the ui to show " | Movie Title" if the year is missing; thus, now i need to create another label control to display only if the year value is missing...

By having the ability to use and IIF statement, we can then "simplify" the code like so:
PHP Code:
<control type="label">
     <
label>IIF(IsMissing($INFO[ListItem.Year]),$INFO[ListItem.Title,$INFO[ListItem.Year] | $INFO[ListItem.Title])</label>
</
control
Now then... the code above will check if the year value is missing, if it is, it will return just the title otherwise it will return the the year, separator and the title, plus we have eliminated the visible tag thereby shortening the code and the need to create additional controls.

This could possible be used with textures as well... Yes, it can become a bit of a pain in the, well..., if there are any nested IIF statements; additionally, I'm not sure if xbmc would take a performance hit with such structure.

Anyway, I apologize if this sounds confusing; I was curious, that's all...
find quote
Hitcher Offline
Skilled Skinner
Posts: 9,931
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #2
If you change the format you can achieve what you're after -

PHP Code:
<label>$INFO[ListItem.Year,, | ]$INFO[ListItem.Title]</label

Displays -

Year | Title

Or -

Title

depending on whether ListItem.Year is empty or not.

[Image: sig_zps3af3b48e.jpg]
(This post was last modified: 2011-07-06 15:02 by Hitcher.)
find quote
`Black Offline
Skilled Skinner
Posts: 2,006
Joined: Apr 2009
Reputation: 49
Location: Germany
Post: #3
If / else statements would generally help to clean up a lot of code. Maybe something like this could be possible then:

Code:
<control type="label">
  <width>if(Skin.HasSetting(foo),850,1250)</width>
  <animation effect="slide" start="0" end="400" time="300" condition="Skin.HasSetting(foo)">Conditional</animation>
  [...]
</control>

[Image: xp1080-21.png]
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 24,523
Joined: Oct 2003
Reputation: 138
Post: #4
Skin variables are the way to do that. There's a ticket already with the basic idea.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


[Image: badge.gif]
find quote
Dom DXecutioner Offline
Member
Posts: 89
Joined: Jan 2010
Reputation: 0
Location: USA
Post: #5
`Black Wrote:If / else statements would generally help to clean up a lot of code. Maybe something like this could be possible then:

Code:
<control type="label">
  <width>if(Skin.HasSetting(foo),850,1250)</width>
  <animation effect="slide" start="0" end="400" time="300" condition="Skin.HasSetting(foo)">Conditional</animation>
  [...]
</control>

Precisely...

Following your logic, while attempting to review and understand the video info xml (confluence), I noticed that most controls were duplicated simply because the data was either movies, tv show or episodes... I noticed that position of the controls were changed and in some cases the info was, too, changed; however, this could have been avoided by simply using conditional statement, which would serve various purposes:
  • Reduce Redundancy
    Having to write the same block of code over, and over and over again to either change the position, size, text or texture can be a bit discouraging; having the ability to reduce such task can become most benificial and time-saving
  • Reduce code footprint; In theory, Better Memory Management
    From what I have read, XBMC's method of managing memory is to not render any particular control unless specifically required, hence <visible></visible> tags; however, if XBMC conforms to programming standards, XBMC (once again, in theory) must allocate memory for any control that will be used in the any given window; albeit, peharps to it's most minimal, but memory needs be reserved, nonetheless (I must re-emphasize, in theory or educated speculation, if you prefer).
  • Simplify Code Management
    I suppose this is somewhat self-explained; small code, less redundancy... in short, a whole lot less lines of code Smile

Pseudo code...

PHP Code:
<control type="image">
     <
posx>IIF(Container.Content(Movies)) , moviesPosX tvshowsPosX)</posx>
     <
posy>IIF(Container.Content(Movies)) , moviesPosY tvshowsPosY)</posx>
     <
width>IIF(Container.Content(Movies)) , moviesWidth tvshowsPosWidth)</width>
     <
height>IIF(Container.Content(Movies)) , moviesHeight tvshowsHeight)</height

As you can see, we could easily use one single image to display what we need irregardless of the container... this can also use nested IIF statements if you wish to use the same image in different containers with different views... additionally, the IIF statement will be used with labels, listitems, textures, etc.

Within the basic construct of the IIF statement, one can easily (imho) conclude that this could potentially be a time-saver when developing skins...

jmarshall Wrote:Skin variables are the way to do that. There's a ticket already with the basic idea.

would you be kind enough to post a link? thank you kindly
find quote
Dom DXecutioner Offline
Member
Posts: 89
Joined: Jan 2010
Reputation: 0
Location: USA
Post: #6
Ok, pardon my ignorance but i've been reading another post about "Variables" and I can't seem to understand as to how this would act as an IIF statement the way jmarshall has indicated. I still believe that conditional statements and nested conditional statement would definately help with code management.

I've recently have had the need to recreate a particular section with the same controls but to display different info, in this case it's RecentlyAdded movies and TVShows... this somewhat doubled my work and code. I could have used the following without the need to replicate the code (pay no attention to the recently added source):
PHP Code:
<!-- [Control.WrapListRecently Added Fanart Content -->
<
control type="wraplist" id="51">
    <
width>636</width>
    <
height>312</height>
    <
onup>3</onup>
    <
ondown>5</ondown>
    <
onleft>51</onleft>
    <
onright>51</onright>
    <
focusposition>0</focusposition>
    <
scrolltime>1000</scrolltime>
    <
viewtype>list</viewtype>
    <
itemgap>10</itemgap>
    <
orientation>horizontal</orientation>
    <
preloaditems>1</preloaditems>
    
    <!-- [
Control.WrapList.ItemLayout] -->
    <
itemlayout width="212" height="312">
            <!-- 
panel fanart image -->
            <
control type="image">
                <
posy>0</posy>
                <
posx>0</posx>
                <
width>208</width>
                <
height>208</height>
                <
aspectratio>stretch</aspectratio>
                <
texture fallback="IIF(Control.HasFocus(2),bg/movieNoFanart.jpg,IIF(Control.HasFocus(3),bg/tvshowNoFanart.jpg))">$INFO[ListItem.Icon]</texture>
            </
control>
            <
control type="image">
                <
posy>212</posy>
                <
posx>0</posx>
                <
width>208</width>
                <
height>208</height>
                <
aspectratio>stretch</aspectratio>
                <
texture>bg/black.png</texture>
            </
control>
            <!-- 
panel content label one -->
            <
control type="label">
                <
posx>8</posx>
                <
posy>244</posy>
                <
width>192</width>
                <
label fallback="n/a">$INFO[ListItem.Label]</label>
                <
font>font11</font>
                <
textcolor>white</textcolor>
                <
align>left</align>
            </
control>
            <!-- 
panel content label two -->
            <
control type="label">
                <
posx>8</posx>
                <
posy>264</posy>
                <
width>192</width>
                <
font>font11</font>
                <
info>ListItem.Label2</info>
                <
textcolor>white</textcolor>
                <
align>left</align>
            </
control>
    </
itemlayout>
    <!-- [
Control.WrapList.FocusedLayout] -->
    <
focusedlayout width="212" height="312">                                    
            <!-- 
Image.Fanart -->
            <
control type="image">
                <
posy>0</posy>
                <
posx>0</posx>
                <
width>208</width>
                <
height>208</height>
                <
aspectratio>stretch</aspectratio>
                <
texture fallback="IIF(Control.HasFocus(2),bg/movieNoFanart.jpg,IIF(Control.HasFocus(3),bg/tvshowNoFanart.jpg))">$INFO[ListItem.Icon]</texture>
            </
control>
            <
control type="image">
                <
posy>212</posy>
                <
posx>0</posx>
                <
width>208</width>
                <
height>208</height>
                <
aspectratio>stretch</aspectratio>
                <
texture>bg/black.png</texture>
            </
control>
            <!-- 
Label.1 -->
            <
control type="label">
                <
posx>8</posx>
                <
posy>244</posy>
                <
width>192</width>
                <
label fallback="n/a">$INFO[ListItem.Label]</label>
                <
font>font11</font>
                <
textcolor>white</textcolor>
                <
align>left</align>
            </
control>
            <!-- 
Label.2 -->
            <
control type="label">
                <
posx>8</posx>
                <
posy>264</posy>
                <
width>192</width>
                <
font>font11</font>
                <
info>ListItem.Label2</info>
                <
textcolor>white</textcolor>
                <
align>left</align>
            </
control>
    </
focusedlayout>
    <!-- [
Control.WrapList.Content] -->
    <
content>
        <
item id="1">
            <
label>01. IIF(Control.HasFocus(2),$INFO[Window.Property(LatestMovie.1.Title)],IIF(Control.HasFocus(3),$INFO[Window.Property(LatestEpisode.1.Title)]))</label>
            <
thumb>IIF(Control.HasFocus(2),$INFO[Window.Property(LatestMovie.1.Fanart)],IIF(Control.HasFocus(3),$INFO[Window.Property(LatestEpisode.1.Thumb)]))</thumb>
            <
onclick>IIF(Control.HasFocus(2),XBMC.PlayMedia($INFO[Window.Property(LatestMovie.1.Path)]),IIF(Control.HasFocus(3),XBMC.PlayMedia($INFO[Window.Property(LatestEpisode.1.Path)])))</onclick>
        </
item>

              ... 
(This post was last modified: 2011-08-18 09:28 by Dom DXecutioner.)
find quote
pieh Offline
Team-XBMC Member
Posts: 656
Joined: Aug 2010
Reputation: 13
Location: Poland
Post: #7
This idea is definitely worth consideration - please follow skin variables topic, using IIF[] (or $IF[condition,value_if_true,optional_value_if_false] more likely) could be shortcut for my idea of skin variables

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

My previous forum/trac nickname: grajen3
find quote
Dom DXecutioner Offline
Member
Posts: 89
Joined: Jan 2010
Reputation: 0
Location: USA
Post: #8
pieh Wrote:This idea is definitely worth consideration - please follow skin variables topic, using IIF[] (or $IF[condition,value_if_true,optional_value_if_false] more likely) could be shortcut for my idea of skin variables
Will do...

To comform to xbmc's current naming convention, you're right, this would more likely be the callout:
PHP Code:
$IF[condition,value_if_true,optional_value_if_false
If nested:
PHP Code:
$IF[condition,value_if_true,$IF[2ndCondition,value_if_true,optional_value_if_false]] 

btw, i got a chance to test your changes; sweet! thanks! while this was not recorded using the nightly build that i tested, the accomplishment is all the same (though easier with your change), check it out: http://www.youtube.com/watch?v=5Gb-XtqbBxo

i'm not working on the current xbmc version too much as previous version of xbmc (camelot) cannot co-exist with recent versions and i need camelot for the xbox (yes, i still have love for the xbox - kinda like a love-hate relationship - lol); i suppose i can always rebuild my other computer that's collecting dust. Smile
(This post was last modified: 2011-08-18 10:16 by Dom DXecutioner.)
find quote
Hitcher Offline
Skilled Skinner
Posts: 9,931
Joined: Aug 2007
Reputation: 67
Location: Eastleigh, UK
Post: #9
Dom DXecutioner Wrote:i'm not working on the current xbmc version too much as previous version of xbmc (camelot) cannot co-exist with recent versions and i need camelot for the xbox (yes, i still have love for the xbox - kinda like a love-hate relationship - lol); i suppose i can always rebuild my other computer that's collecting dust. Smile

I use two builds of XBMC (Dharma and Nightly) by using the portable mode for Dharma and giving it a different install folder name.

[Image: sig_zps3af3b48e.jpg]
find quote
Dom DXecutioner Offline
Member
Posts: 89
Joined: Jan 2010
Reputation: 0
Location: USA
Post: #10
Hitcher Wrote:I use two builds of XBMC (Dharma and Nightly) by using the portable mode for Dharma and giving it a different install folder name.
hmp! portable mode you say... i'll have to check that out; thanks for the tip.
find quote