Sie sind nicht angemeldet.

Scott Witte

Fortgeschrittener

  • »Scott Witte« ist der Autor dieses Themas

Beiträge: 382

Wohnort: Milwaukee, WI USA

Beruf: Professional Photographer

  • Nachricht senden

1

Donnerstag, 15. Juli 2021, 04:36

Calc without ";" error?

Kind of a head-scratcher for me. why does
if(layer[scrolltextfield].width GT calc(stagewidth - 30), calc(layer[scrolltextfield].width, stagewidth - 30));
fail with the error: "Invalid expression: layer[scrolltextfield].width, stagewidth - 30 tour.js line 10 > eval:1:133792:

While
if(layer[scrolltextfield].width GT calc(stagewidth - 30), calc(layer[scrolltextfield].width, stagewidth - 30););
does not? The only difference is the addition of a semicolon (in red) that I wouldn't think is necessary. The error occurs in Firefox and Chrome.

Tuur

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Nachricht senden

3

Donnerstag, 15. Juli 2021, 12:21

Hi,

i would try something like:

Quellcode

1
2
calc(_sw, stagewidth - 30);
if(layer[test].width GT _sw, copy(layer[test].width, _sw));




Hope it helps,
Tuur *thumbsup*

Scott Witte

Fortgeschrittener

  • »Scott Witte« ist der Autor dieses Themas

Beiträge: 382

Wohnort: Milwaukee, WI USA

Beruf: Professional Photographer

  • Nachricht senden

4

Freitag, 16. Juli 2021, 05:11

Thanks for the suggestion, Tuur. It should work but adding the extra semicolon also works. I am just curious why it would be necessary since you don't need to separate the last calc() from anything following. Note that the calc() earlier in the line doesn't need a semicolon. The examples in the documentation also don't use an extra semicolon. So, either it is a bug or a logic fault on my part. But which?

Beiträge: 770

Wohnort: Russian Federation

Beruf: Interpreting, Building virtual tours

  • Nachricht senden

5

Freitag, 16. Juli 2021, 09:59

Hi )

As far as I understand it 'calc()' (without semicolon) is a 'parameter in action' while 'calc();' is an action. You can use first one inside comparisons.

see this line in documentation:

The calc(expression) action is a special action that can be only used as parameter when calling other actions or when accessing array elements.



Therefore, 'if(A GT calc(B - 10), do_smth();); is OK and 'if(A GT calc(B - 10); , do_smth(); );' might throw an error.


Or like this one:


set(A, calc(B - 10));
or shorter would be:
calc(A, B - 10);
Regards,

Alexey

6

Freitag, 16. Juli 2021, 11:16

yes calc() is a special case.
i remember mails w klaus about this, but forgot the rules .-)

calc(expression) differs from calc(dest, expession)
the first one is used in comparisons or instead of get() for example
for the latter you need a semicolon in some cases.

in this example its not obvious to me, too
why calc() doesn't recognize its 2 arguments and tries to evaluate both as one expression *confused*

Beiträge: 770

Wohnort: Russian Federation

Beruf: Interpreting, Building virtual tours

  • Nachricht senden

7

Freitag, 16. Juli 2021, 12:46

Seems it's impossible to use calc() without semicolon and WITH destination variable:

Quellcode

1
trace(calc('test' + '_me'));	 trace(calc('test' + '_me'););	 trace(calc(dest, 'test' + '_me'));


First two traces work the same, while the third one fails.
Regards,

Alexey

Beiträge: 1 117

Wohnort: Poland, Europe

Beruf: krpano developer : virtual tours : the cms4vr owner

  • Nachricht senden

8

Freitag, 16. Juli 2021, 12:49

trace(calc(dest, 'test' + '_me')); => trace(calc(dest + 'test' + '_me')); *thumbup*
Your own professional, online cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: youtube :: wiki.cms4vr.com

cms4vr team *thumbsup*

9

Freitag, 16. Juli 2021, 18:35

if(true, calc(test,5+3)); --> test = null
if(true, calc(test,5+3);); --> test = 8

you need the semicolon, the question is why :)
my bet is, internally 2 separate functions, one has 1 parameter, one has 2 parameters

Scott Witte

Fortgeschrittener

  • »Scott Witte« ist der Autor dieses Themas

Beiträge: 382

Wohnort: Milwaukee, WI USA

Beruf: Professional Photographer

  • Nachricht senden

10

Freitag, 16. Juli 2021, 21:41

Hmmm. Well at least we know that calc(dest, expression); always requires a terminating semicolon whereas calc(expession) does not -- for whatever reason.

Klaus -- it might be good to state this explicitly in the documentation.

Thanks, guys, for clearing that up.

11

Mittwoch, 21. Juli 2021, 11:06

Hi,

right, there are two different 'calc' cases:

- one is a normal action call

Quellcode

1
calc(result, expression);


- and the other is special case to evalute an expression before passing its result to an action:

Quellcode

1
someaction( calc(expression) );


I have tried showing that also here in the documentation:
https://krpano.com/docu/actions/#calc

That parser of the action calls doesn't know it in advance if an action might get a callback string or just a normal parameter and because the parameters are type-less it can't differ between action-calls and strings. And further the parsing of the given parameters of an action happens in a later parsing step, so it can't count the number of the parameters in advance to differ between both cases.

That means an action( calc(...) ) call always results in the second case, but when ending the calc with ';' or adding other actions to the call, it is not longer a valid get/calc parameter call and the parameters is handled as normal string parameter.

That also means a calc(dest, expression) doesn't 'always' requires a terminating semicolon, but it would require one, when using that in a parameter of another action call.

I will try adding that case a special note in the documentation.

Best regards,
Klaus

Scott Witte

Fortgeschrittener

  • »Scott Witte« ist der Autor dieses Themas

Beiträge: 382

Wohnort: Milwaukee, WI USA

Beruf: Professional Photographer

  • Nachricht senden

12

Mittwoch, 21. Juli 2021, 19:20

Thanks, Klaus.

It is slowly making more sense to me. set(result, calc(expression)); vs calc(result, expression);

13

Mittwoch, 21. Juli 2021, 21:13

...

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »indexofrefraction« (27. Juli 2021, 09:12)