Own Javascript does not return a value

  • Автор темы Автор темы Paginator
  • Дата начала Дата начала

Paginator

Client
Регистрация
30.09.2012
Сообщения
7
Реакции
0
Баллы
0
Hello,

I got the following code running in Zenno 4.2.5.0 which does not return a value.


Код:
Развернуть Свернуть Копировать
var url = {-Variable.LinkItem-};
var regex = /^http/;
if(!regex.test(url)) {
	return "http://example.com" + url;
} else {
	return url;
}
Even if I try this, nothing returns:

Код:
Развернуть Свернуть Копировать
return "http://someurl.any";

I also assigned the return value to a variable via "Put result to variable".

What is wrong with the code, or its a bug?


Greetings

Paginator
 
I investigated that return does not work. Although it is described in the documentation of Zenno 3.

To get the final value you should either write return followed by the name of the variable whose value the macro executing your JavaScript code is supposed to return, or simply write this variable at the end, and the macro will return the value of the very last variable used in your JavaScript code.

Second problem is - if you use a {-foo-} variable to assign another variable.
If you do that, the script does not work. In my case it is the following statement:
var url = {-Variable.LinkItem-};

Also string concatination with a {-foo-} variable does not work (see my comment below)

But how can I solve my problem above without assigments?

var result = 'narf';
var regex = /^http/;
if(!regex.test({-Variable.LinkItem-})) {
//This is also not possible - but why?
result = "http://example.de" + {-Variable.LinkItem-};
} else {
// Is there another way to do this?
result = {-Variable.LinkItem-};
}
 
Don't know if this will actually help or not, but have you tried declaring the variables first outside of the javascript and then bringing them in? I'm no javascript master, just thought it might help.
 
If you want to return value of var x; then just write x; at the end of JS.
To set string value you should put {-Variable.LinkItem-}; into double quotes, like this "{-Variable.LinkItem-}";
 
I would suggest to make zennoposter javascript tester somewhere online. To give access to everyone... Because i have hard time to make javascript working. I hire freelancer, but the only way i found was to give him my zenno licence to test javascript...
 
I tried everthing posted - no results :(
Even with:
Код:
Развернуть Свернуть Копировать
var regex = /^http/;
if(!regex.test({-Variable.LinkItem-})) {
	 {-Variable.result-} = http://example.de" + "{-Variable.LinkItem-}";
} else {
	{-Variable.result-} =  "{-Variable.LinkItem-}";
}
{-Variable.result-};
 
-- deleted same post occured two times --
 
*bump*

What are the differences between normal Javascript and "Zennoposter-Javascript"?

Can not get my code running...
 
Hi Paginator, check the starting double quote in line 3.

Also, did you tried what Hungry Bulldozer suggested about enclosing the variable with " "? -> "{-Variable.result-}";

I tried everthing posted - no results :(
Even with:
Код:
Развернуть Свернуть Копировать
var regex = /^http/;
if(!regex.test({-Variable.LinkItem-})) {
	 {-Variable.result-} = [B]"[/B]http://example.de" + "{-Variable.LinkItem-}"; 
                               [B]^missing double quote[/B]
} else {
	{-Variable.result-} =  "{-Variable.LinkItem-}";
}
{-Variable.result-};
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)