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
 Calling Procedures
PostPosted: Sat Jul 27, 2013 12:12 pm 
Offline
Regular
User avatar
Hey there, I'm new to the forum, and I'm interested in creating and potentially sharing some scripts, depending on how happy I am with the outcome.

I've got a little programming history in c#, but beyond that, not much at all. I can easily read and write .groovy scripts, but there are some more advanced functions I'd like to do.

This function in particular *could* be done without this, but it would make script files much smaller in size and length, and be much more manageable.

What I'm looking to do is for punishments. In my script there are say, 5 punishments that you could recieve. You recieve these at random, so wherever a punishment could occur, it could be one of any of these five.
now, I know that I could pick this from a random integer that is picked from 0-array length, where the length of the array is how many punishments I have.

I could insert these punishment blocks in at each punishment place, but that would make it more difficult to manage than it needs to be.

I would like to call an entire block of code, where a number (the array) pertains to which block to use.

Inside a block there are multiple things, so the script is to be quite advanced. All the more reasoning to define the block once. I'm pretty confident I can handle all of it, except for defining and running these blocks at multiple places, while only having the block defined once. It also helps in case I want to change any of the punishments. There's also potential for users to define their own punishments for this script specifically and use them, but I'm not that quite advanced in this language yet.

Could anyone with a bit more experience shed some light on the matter? cheers!


Top
 Profile Send private message 
 
 Re: Calling Procedures
PostPosted: Sat Jul 27, 2013 12:26 pm 
Offline
Regular
User avatar
I should probably mention that I'd like it for after the punishment to return to the place that it was at prior to recieving the punishment, if at all possible.

For example, say I'm on line 30. In line 31, I recieve a punishment (and the random punishment is picked). The punishment's line is located at line 400. After completing line 400, I would be returned to line 30, and re try in order to not get the punishment.

edit; I probably should've put this in the main post via edit. My bad.


Top
 Profile Send private message 
 
 Re: Calling Procedures
PostPosted: Sat Jul 27, 2013 3:18 pm 
Offline
Site Admin
User avatar
You can do real procedures, there is a full usual syntax in Groovy for that. See for example this thread from wololo.
Quite example :
Code:
def p1 = { s1, s2 -> showMessage(s1+", "+s2) }
p1("Up", "now !")


Top
 Profile Send private message 
 
 Re: Calling Procedures
PostPosted: Sat Jul 27, 2013 3:56 pm 
Offline
Regular
User avatar
Thanks for the speedy reply! I was honestly expecting to have to wait for days, these kinds of communities tend to be quite inactive I've found.

Thanks for your example, but can this work for multiple lined blocks? a quick example for what I'm trying to do below in pseudocode-eqsue format.

START story
Dialogue/Other etc
Dialogue/Other etc
Option
.. If Player chooses wrong option.
.. ... START punishPlayer
.. ... int RandNum = Random(NumberOfPunishments);
.. ... Punishment = Punishment(RandNum);
.. ... Do(Punishment())
.. ... END punishPlayer
..else
Dialogue/Other etc
...Option (repeat block)
Dialogue/Other etc
END story

START Punishment(1)
do A.
do B.
END Punishment(1)

START Punishment(2)
do X.
for Y long.
END Punishment(2)

If what you've posted is what makes this possible and I haven't realized, sorry about that. I've become a bit rusty, and even then I wasn't very good at c# either. And this is also another language. If I've missed something in your post, or had you confused with something else, would you please be able to repost with a bit more depth? If it's the same thing, Wololo's example was a little hard for me to follow also.

Thanks

edit; Also adding this; All of my knowledge across all programming has been self taught, so many things aren't as obvious as they should be to me, etc. May put a bit more context to why I'm not understanding something that may be simple to those with the know-how.


Top
 Profile Send private message 
 
 Re: Calling Procedures
PostPosted: Sat Jul 27, 2013 5:19 pm 
Offline
Site Admin
User avatar
Here is how I'd do this, 2 solutions :
Code:
def doPunishment1 = {
  ...
}

def doPunishment2 = {
  ...
}
...
if(...) {
  def n = 1 + getRandom(2)
  switch(n) {
  case 1: doPunishment1(); break
  case 2: doPunishment2(); break
  }
}
...


Code:
def doPunishment = { n ->
  switch(n) {
  case 1:
    ...
    break
  case 2:
    ...
    break
  }
}
...
if(...) {
  doPunishment(1+getRandom(2)) 
}
...


(in both solution, the number of punishments may be in a variable)


Top
 Profile Send private message 
 
 Re: Calling Procedures
PostPosted: Sat Jul 27, 2013 6:19 pm 
Offline
Regular
User avatar
I don't have access to try this right now and wont for a while, but just to clarify;

I can define the action with

def PunishmentName = {
code
}

and then can later use just "PunishmentName();" to actually call and do the block?

That seems a lot easier than I would've thought!


Top
 Profile Send private message 
 
 Re: Calling Procedures
PostPosted: Sun Jul 28, 2013 8:18 am 
Offline
Regular
User avatar
I've tried this and got it working, had some fun with it.

Thanks a lot for your help doti!

I've already begun (trying to) write something more 'proper' and in depth. Not sure how this is going to go. I think I can program any of the stuff I can come up with, but I'm not sure about my actual writing skills. See where we end up.


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 11 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.