how to reduce repetitiveness of code please?

  • Hi,

    I have a tour with 6 very large rooms and each room has 3 X 360 degree images. I'd like each group of 3 scenes to have an 'Open Info' button which opens a small info screen showing info specific for that room. In the case of the first room the button would open 'info_1.png' and I have 4 other info screens for the remaining groups 4 rooms each with 3 scenes.

    I have the 'Open Info' button down on the Navbar which when clicked opens the info screen (info_1.png) no problem and at the same time changes the button to 'Close Info'. It works well for the job.

    I'm thinking there must be an alternative solution to applying the following code to 18 scenes and changing the 'skin_plan' on each group of 3 to info_1.png, info_2.png, info_3.png etc. There's too much repetitiveness

    Code
    <layer name="skin_btn_plan" url="vtourskin.png" crop="0|320|120|64" align="right" x="110" y="-1" scale="0.6" onclick="set(layer[skin_plan].visible,true); set(layer[skin_btn_plan].visible,false); set(layer[skin_closeplan].visible,true" ondown="skin_buttonglow(null);" onhover="showtext(OPEN INFO,buttonstyle);" onup="skin_buttonglow(null);"/>
        
    <layer name="skin_closeplan" keep="true" url="vtourskin.png" crop="0|375|130|64" align="right" x="110" y="-1" scale="0.6" visible="false" enabled="true" zorder="2" onclick="set(layer[skin_plan].visible,false);set(layer[skin_btn_plan].visible,true); set(layer[skin_closeplan].visible,false" ondown="skin_buttonglow(null);" onhover="showtext(CLOSE INFO,buttonstyle);" onup="skin_buttonglow(null);"/>
       	 
    <layer name="skin_plan" keep="true" url="info_1.png" align="center" x="0" y="-300" alpha="1" visible="false" enabled="false"/> 	 </layer>

    Is there any way I can just have one instance of the code above applying to a group of 3 scenes, then a single instance for another group of 3 scenes, but change to info_2.png etc?

    Hope that make sense as it took me a few tiles to write it out *confused*

    Thanks.

  • Hi! I would apply a "tag" inside the scene node to define which info button this scene must open:

    Code
    <scene name="your_scene" tag="info_1" ... ></scene>
    <scene name="your_scene_2" tag="info_2" ... ></scene>....

    Then, your info button should perform an action like this (checking the tag of the current scene):

    Code
    if(scene[get(xml.scene)].tag == info_1, set(layer[info_1].visible, true);); if(scene[get(xml.scene)].tag == info_2, set(layer[info_2].visible, true);); .....

    and the same method for "info_close" button:

    Code
    if(scene[get(xml.scene)].tag == info_1, set(layer[info_1].visible, false););if(scene[get(xml.scene)].tag == info_2, set(layer[info_2].visible, false);); ....

    I would go this way, at least *smile*

    Regards,

    Alexey

  • Hi Alexey,

    Thanks for your time getting back to me. I've no idea how you came up with that but it certainly looks good. I've tired several times to implement it but I don't think I'm going about it correctly, or at least what you had in mind.

    This is the complete code for one of the scenes and as is it works by displaying the 'Open Info' button on the bottom right which when clicked opens info_1.png and changes the button to 'Close Info' button. The only way for me to make this work for all the scenes is to add the same code to everyone but change a few things here and there as I have 4 more info png's.

    Note that I added tag="info_1" on there also as you mentioned and did the same for the other 2 scenes of the same room. The other rooms have tag="info_2", tag="info_3" etc. and I'm also using the newer version of the Auto Map plugin which is excellent.


    With your method I'm not too sure which part of the above code I would replace with your example code?

    Thanks again,

    Andrew

  • Duplicate the "skin_plan" layer:

    Code
    <layer name="skin_plan" keep="true" url="images/info_1.png" ... /><layer name="skin_plan_2" keep="true" url="images/info_2.png"...

    Layer "skin_btn_plan" should have

    Code
    onclick="open_info();"

    and this action as I wrote in my previous post:

    Code
    <action name="open_info" >if(scene[get(xml.scene)].tag == info_1, set(layer[skin_plan].visible, true););  if(scene[get(xml.scene)].tag == info_2, set(layer[skin_plan_2].visible, true););  </action>

    Layer "skin_closeplan" should have

    Code
    onclick="close_info():"

    and this action:

    Code
    <action name="close_info" >if(scene[get(xml.scene)].tag == info_1, set(layer[skin_plan].visible, false);); if(scene[get(xml.scene)].tag == info_2, set(layer[skin_plan_2].visible, false););  </action>

    Regards,

    Alexey

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!