Own Javascript does not return a value

Paginator

Client
Joined
Sep 30, 2012
Messages
7
Reaction score
0
Points
0
Hello,

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


Code:
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:

Code:
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
 

Paginator

Client
Joined
Sep 30, 2012
Messages
7
Reaction score
0
Points
0
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-};
}
 

bigcajones

Client
Joined
Feb 9, 2011
Messages
1,228
Reaction score
685
Points
113
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.
 

Hungry Bulldozer

Moderator
Joined
Jan 12, 2011
Messages
3,441
Reaction score
837
Points
113
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-}";
 

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,919
Reaction score
1,203
Points
113
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...
 

morpheus93

Client
Joined
Jan 25, 2012
Messages
1,068
Reaction score
257
Points
83

lokiys

Moderator
Joined
Feb 1, 2012
Messages
4,919
Reaction score
1,203
Points
113

Paginator

Client
Joined
Sep 30, 2012
Messages
7
Reaction score
0
Points
0
I tried everthing posted - no results :(
Even with:
Code:
var regex = /^http/;
if(!regex.test({-Variable.LinkItem-})) {
	 {-Variable.result-} = http://example.de" + "{-Variable.LinkItem-}";
} else {
	{-Variable.result-} =  "{-Variable.LinkItem-}";
}
{-Variable.result-};
 

Paginator

Client
Joined
Sep 30, 2012
Messages
7
Reaction score
0
Points
0
-- deleted same post occured two times --
 

Paginator

Client
Joined
Sep 30, 2012
Messages
7
Reaction score
0
Points
0
*bump*

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

Can not get my code running...
 

hookpilot

Новичок
Joined
Sep 24, 2012
Messages
7
Reaction score
0
Points
0
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:
Code:
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-};
 

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)