Sie sind nicht angemeldet.

1

Mittwoch, 11. Januar 2012, 15:54

Variable name in variable

Hi.

I'm having problems with variables. I have a variable name in a variable, and I just can't find any way to get the original value through the two variables. Confusing? Well, here's a simplified example.

Quellcode

1
<hotspot name="hs-1934" onloaded="set(desc-hs-1934, 'Description of the hs')"  style="style_hs" onhover="showtext();" />

Next, I would like to have only one action, like this.

Quellcode

1
<action name="showtext">showtext(get(desc-get(name)));</action>

But it doesn't work and it seems to me that I cannot have get inside get? Is there another way to resolve the original content of the variable? I don't want to write thousand actions just for the showtext-action.

Zephyr

Profi

Beiträge: 1 003

Wohnort: Netherlands

Beruf: Web developer

  • Nachricht senden

2

Mittwoch, 11. Januar 2012, 16:13

try:

Quellcode

1
2
3
4
5
<hotspot name="hs-1934" onloaded="set(desc-hs-1934, 'Description of the hs')"  style="style_hs" onhover="show_text();" />
<action name="show_text()">
txtadd(tmp, 'desc-', get(name));
showtext(get(tmp));
</action>


alsoo dont name your actions the same as krpano build in functions

Alsoo I dont know why you use onloaded. This would be better:

Quellcode

1
2
3
4
<hotspot name="hs-1934" description="Description of the hs"  style="style_hs" onhover="show_text();" />
<action name="show_text()">
showtext(get(description));
</action>

3

Mittwoch, 11. Januar 2012, 16:28

It was just an example which I wrote for this topic. Well, your first example just shows the name of the variable, not the value. I've tried that one and that's where is my problem. I can't figure out the value of the variable through another variable. But thanks for the second code, didn't realize there's a description itself. But still, how to get a variable through another variable? Any other programming language I know can do that.

4

Donnerstag, 12. Januar 2012, 17:17

Hi,

this would work:

Quellcode

1
copy(var_content, get(var_with_varname));


as example:

Quellcode

1
2
3
4
5
6
7
<hotspot name="hs-1934" onloaded="set(desc-hs-1934, 'Description of the hs')"  style="style_hs" onhover="show_text();" ... />

<action name="show_text">
txtadd(var_with_varname, 'desc-', get(name));
copy(var_content, get(var_with_varname));
showtext(get(var_content));
</action>


best regards,
Klaus