de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Methods in groovy/sscript
PostPosted: Thu Apr 12, 2018 11:33 am 
Offline
Regular
If I look into groovy documentation a method in groovy looks like so:

Code:
int fib(int n) {
    n < 2 ? 1 : fib(n-1) + fib(n-2)
}

http://groovy-lang.org/structure.html#_methods

But with sscript this does not seem to work. The syntax check complains something about method definition not expected here.

In all the scripts I have looked methods are defined and called like so:

Code:
def xyz = { argument ->
  // do something
}

xyz("test")


Is this some kind of special sscript stuff or standard groovy stuff which I have not yet stumbled over?


Top
 Profile Send private message 
 
 Re: Methods in groovy/sscript
PostPosted: Thu Apr 12, 2018 3:15 pm 
Offline
Addict
Hi vladl,

the thing you see in the scripts and your second example is a closure. This is a regular groovy-structure, see http://groovy-lang.org/closures.html.

Groovy is kind of picky when it comes to places and contexts where methods can be defined and where they can't. For example it's not possible to define them inside of other methods or closures.

Closures on the other hand may basically be defined everywhere. For the other differences between these structures like variable-scope etc. please see the documentation.

I don't know if the scripts are run within a hierachy like a closure of the main program in sexscripts. This is something doti would have to answer. But if this is the case, then methods will not work, but closures will still do. So I suggest you try to use these.


Regards

cgut2001


Top
 Profile Send private message 
 
 Re: Methods in groovy/sscript
PostPosted: Thu Apr 12, 2018 5:02 pm 
Offline
Regular
Many thanks cgut2001


Top
 Profile Send private message 
 
 Re: Methods in groovy/sscript
PostPosted: Thu Apr 12, 2018 5:33 pm 
Offline
Site Admin
User avatar
Yes, all the script code is itself inside a method, so you can only create closures


Top
 Profile Send private message 
 
 Re: Methods in groovy/sscript
PostPosted: Thu Apr 12, 2018 5:48 pm 
Offline
Addict
doti wrote:
Yes, all the script code is itself inside a method, so you can only create closures


Thanks for the information, doti


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.