This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 12 - Pages: 1 - Last Post: 12 Oct 22, 20:40 Last Post By: JeffTucker Threads: [ Previous | Next ]
ctwist

Posts: 609
Registered: 27-Sep-2003
Groovy persistence problem
Posted: 24 Sep 22, 19:30
 
  Click to reply to this thread Reply
I am converting my BeanShell scripts to Groovy.

All the scripts call compiled Java classes, so there is very little Groovy code.

init.bsh contains
MgAlbum mgAlbum = new MgAlbum(engine);
and predir.bsh contains
if (level == 0)
{ mgAlbum.albumInit(); }
When I run this in Groovy, predir.groovy reports an error:
se.datadosen.util.ScriptException: groovy.lang.MissingPropertyException: No such property: mgAlbum for class: predir in predir.groovy

What am I doing wrong?
JeffTucker

Posts: 8,462
Registered: 31-Jan-2006
Re: Groovy persistence problem
Posted: 24 Sep 22, 20:30   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
Not sure, since I'm not calling any compiled routines from my Groovy scripts. But a hunch - in init.groovy, I would try just:
mgAlbum = new MgAlbum(engine)
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Groovy persistence problem
Posted: 24 Sep 22, 20:43   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
I am converting my BeanShell scripts to Groovy.
Dumb question, but why can't you do it all in init.groovy?
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Groovy persistence problem
Posted: 24 Sep 22, 21:18   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
Not sure, since I'm not calling any compiled routines from my Groovy scripts. But a hunch - in init.groovy, I would try just:
mgAlbum = new MgAlbum(engine)
I have found I can't use things in Groovy that you could in .bsh, like variableName;
Groovy reports 'No such property: for variableName in init.'

I have to either assign a value or use def or String/int etc. variableName. As as mentioned somewhere else, for ao.getVars.get("variableName") I have to use int not def for an integer (custom ui used in the skin).
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Groovy persistence problem
Posted: 24 Sep 22, 22:29   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
Not sure, since I'm not calling any compiled routines from my Groovy scripts. But a hunch - in init.groovy, I would try just:
mgAlbum = new MgAlbum(engine)
That could work, I have just found out that in init, outside any method,
DecimalFormat df = new java.text.DecimalFormat("#.##");
df.setMaximumFractionDigits(4);
Fails when df is used within a method. def df... also fails. Lo and behold just using
df = new java.text.DecimalFormat("#.##");
works.

The original code works if used within the method.
JeffTucker

Posts: 8,462
Registered: 31-Jan-2006
Re: Groovy persistence problem
Posted: 24 Sep 22, 22:43   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
That's become one of my go-to solutions for some of the puzzling errors. Just get rid of the type declaration! I think that has the effect of making it global.
RobM

Posts: 4,380
Registered: 4-Aug-2006
Re: Groovy persistence problem
Posted: 24 Sep 22, 23:21   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker

Posts: 8,462
Registered: 31-Jan-2006
Re: Groovy persistence problem
Posted: 24 Sep 22, 23:25   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
I saw that statement, too, and I thought, "Well, I'm certainly glad we cleared that up!"

And to think, I've managed to convert all of my skins to Groovy without installing the Zovuvazz Framework™.
ctwist

Posts: 609
Registered: 27-Sep-2003
Re: Groovy persistence problem
Posted: 25 Sep 22, 01:09   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
Not sure, since I'm not calling any compiled routines from my Groovy scripts. But a hunch - in init.groovy, I would try just:
mgAlbum = new MgAlbum(engine)
No that doesn't work.

RobM wrote:
Dumb question, but why can't you do it all in init.groovy?
jAlbum does some initialisation between init.groovy and predir.groovy (i.e. create output folders and initialise engine). I need this to be complete.

It seems to me that objects declared in init.groovy are local, whereas in init.bsh, such objects are global. I have done some research about how to declare global variables in Groovy, but the recommendations are as clear as mud.

I will probably stick with BeanShell. It works. There is no compelling reason to abandon it.
davidekholm

Posts: 4,405
Registered: 18-Oct-2002
Re: Groovy persistence problem
Posted: 26 Sep 22, 13:40   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
That's become one of my go-to solutions for some of the puzzling errors. Just get rid of the type declaration! I think that has the effect of making it global.

Correct
davidekholm

Posts: 4,405
Registered: 18-Oct-2002
Re: Groovy persistence problem
Posted: 26 Sep 22, 13:42   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
ctwist wrote:
JeffTucker wrote:
Not sure, since I'm not calling any compiled routines from my Groovy scripts. But a hunch - in init.groovy, I would try just:
mgAlbum = new MgAlbum(engine)
No that doesn't work.

How do you mean? What error do you get in predir.groovy if you declare your variable without a type? (That should make it globally visible)
ctwist

Posts: 609
Registered: 27-Sep-2003
Re: Groovy persistence problem
Posted: 12 Oct 22, 19:07   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
After a short hiatus, I am back.

The problem that I reported is working now. As I look back at my changes, I can't see what I was doing wrong. Anyway there is no point in discussing this further.
JeffTucker

Posts: 8,462
Registered: 31-Jan-2006
Re: Groovy persistence problem
Posted: 12 Oct 22, 20:40   in response to: ctwist in response to: ctwist
 
  Click to reply to this thread Reply
I routinely have those kinds of moments. "I could swear I did exactly the same thing before, and it didn't work. Now it does."
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums