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


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Functions in other files (or other files as functions)
PostPosted: Thu Jun 05, 2014 12:16 am 
Offline
Shy
I've been planning out an ambitious 24/7 script for a while (in all likelihood too ambitious to ever finish), and just started coding it. I'm running into a few issues, which I'm not sure is due to my inexperience with the SexScripts API and groovy (python has been my language of choice for this kind of scripting, but after getting started it doesn't feel too different), or if it's because SexScripts is designed more for short routine style scripts than the 24/7 Jewell-inspired script I'm trying to create.

After reading through the documentation, and the code for Jewell, I can't find a way to do this. I'm trying to find a way to call functions in other .groovy files (essentially using them as libraries). Alternatively, is there a way to call another .groovy file itself as a function? The only method I've found for transferring execution to other files is return "scriptname", which is rather limiting. You can't pass arguments, although I suppose you could do a work-around by having the calling script save them temporarily as keys in data.properties and then the callee script load them, but that's kind of an ugly solution. The other major limitation is that I can't return code execution to the place I was at in the main script, I have to start from the beginning, which is how Jewell accomplishes it. The main script returns the sub-script, then the sub-script returns back to the main script, which again feels like an ugly workaround.

The 24/7 script I'm planning is more dynamic and responsive than Jewell, and will require moving a lot of data around, such as the sub's likes and dislikes to influence tasks. As an example, the script would keep track of the sub's pain tolerance. 20 spanks with a paddle might be the equivalent of a severity 3 punishment in the Jewell script for a sub with a high pain tolerance, but it might be a 6 or a 7 for a sub with a low pain tolerance. I feel this would work better with more traditional programming methods of calling functions. I suppose I could use my own defined functions if I put everything in one giant .groovy file, but I'd rather not do that. If these kind of workarounds are the only way to accomplish what I'm trying to do, that's fine (although in that case I might want a copy of the SexScripts source code and see if I can't modify it to do what I want.). I'm just wondering if there's a better way to accomplish this that I'm missing.

Edit: Another issue I'm running into: There's functions for loadInteger, loadString, etc. What about a way to save and load more complex types like maps and lists? Or, since groovy is dynamically typed anyway, what about a generic load("key")?


Top
 Profile Send private message 
 
 Re: Functions in other files (or other files as functions)
PostPosted: Sat Jun 07, 2014 11:11 am 
Offline
Site Admin
User avatar
You're perfectly right about the similarities of Python and Groovy.

Also, you're right in your discovering ; there's no way to make a casual library in SexScripts groovy. This is intentional, for quite a lot of reasons.

You'll find some workaround about saving lists here.


Top
 Profile Send private message 
 
 Re: Functions in other files (or other files as functions)
PostPosted: Sat Jun 07, 2014 10:51 pm 
Offline
Shy
I see. Could you elaborate on the reasons that you can't use libraries or return code execution to the point that it left off when finishing a sub-script? Are they philosophical reasons, as in "I don't think people should write scripts that work this way", or would it just be difficult to implement? I'm trying to come up with better workarounds that wouldn't require a headache every time I try to move between .groovy files, or decide if I should just not use SexScripts at all and write my own software from scratch instead. I'd like to avoid that, as my experience with UI programming is essentially nil, and I'd prefer to spend my time coding fun things rather than the boring behind the scenes stuff.

The one workaround I've thought of so far is to use separate files as libraries, and have an initialization script that the user first opens, which would read all the libraries and combine them, saving the result into one giant .groovy file, starting with the "main" program loop at the top. Then a return statement would transfer execution to the combined file. I haven't actually tried this yet, so I'm not sure how well it would work.

Apologies if I sound like I'm being critical of SexScripts. It's a very nice piece of software, I'm just not entirely convinced it's the right tool for the job that I'm trying to do.


Top
 Profile Send private message 
 
 Re: Functions in other files (or other files as functions)
PostPosted: Sun Jun 08, 2014 12:21 pm 
Offline
Site Admin
User avatar
If you decide to create another tool, don't hesitate to publish it here.

To lower the bar for creating scripts, not application, there are some limitation to be made ; there's a whole litterature about that. 90% is easier, 10% is a lot harder. Among goals, being able to understand, even without being a real programmer, source code of others. Librairies are not a simple thing (that's why there's quite a few way of doing it, think c/c++ vs Java vs Python, 3 ways for 3 similar languages).
Anyway, if you understand it (and security consequences of it), you can use the Groovy Classloader :
  • create a sub folder for your library in "scripts/"
  • inside, create groovy classes like below
  • class it with code below
  • publish them with your scripts

A Groovy class (scripts/myscript/Class1.groovy) :
Code:
class Class1 {
  def static getText() {
     "Red "
  }
  def static getText2 = { "panties !" }
  def static showSomething = {main, str -> main.show(str) }
}


The code for calling it (scripts/myscript.groovy) :
Code:
def cl = new groovy.lang.GroovyClassLoader();
cl.addClasspath("scripts/myscript/")
def class1 = cl.loadClass("Class1")
//...
def str = class1.getText()+" "+class1.getText2()
class1.showSomething(this, str)


Top
 Profile Send private message 
 
 Re: Functions in other files (or other files as functions)
PostPosted: Fri Sep 26, 2014 4:52 am 
Offline
Active member
That's the missing code I too was looking for. Thank you for highlighting this. It's the class path I couldn't figure out where to put. Groovy couldn't find my class and threw a very unhelpful error.

I too have common fuctions across files, things to do beat repetition or any kind of common loop (like metronome).

Would you consider incorporating a metronome function into the API if I wrote it?

Something like waitWithMetro("message blah blah", BPM, length, timeout);

doti wrote:

A Groovy class (scripts/myscript/Class1.groovy) :
Code:
class Class1 {
  def static getText() {
     "Red "
  }
  def static getText2 = { "panties !" }
  def static showSomething = {main, str -> main.show(str) }
}


The code for calling it (scripts/myscript.groovy) :
Code:
def cl = new groovy.lang.GroovyClassLoader();
cl.addClasspath("scripts/myscript/")
def class1 = cl.loadClass("Class1")
//...
def str = class1.getText()+" "+class1.getText2()
class1.showSomething(this, str)


Top
 Profile Send private message 
 
 Re: Functions in other files (or other files as functions)
PostPosted: Sat Sep 27, 2014 9:54 am 
Offline
Site Admin
User avatar
It may be added as a bunch of other functions


Top
 Profile Send private message 
 
 Re: Functions in other files (or other files as functions)
PostPosted: Sat Sep 27, 2014 8:33 pm 
Offline
Active member
doti wrote:
It may be added as a bunch of other functions


Excellent, I wrote a basic metro ...
viewtopic.php?f=4&t=436

Please consider it as a contribution and we can make writers lives a lot eaiser (not saying this is the only type of metronome you should have) and scripts better.


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

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 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.