[EOS] creating a subroutine

Post all technical issues and questions here. We'll gladly help you wherever we can.
Post Reply
User avatar
ritewriter
Explorer At Heart
Explorer At Heart
Posts: 326
Joined: Sun Jan 02, 2022 6:51 am
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Switch
Contact:

[EOS] creating a subroutine

Post by ritewriter »

Hey, does anyone know if there’s a way to create a callable subroutine that will run a series of commands. Something I can create in init then call with an eval?

I’m trying to have something that will run this when triggered:

Eval
rand=Math.floor(Math.random() * (100 - 1 + 1)) + 1;

If rand<11

>Then (Eval willcheck=) (Say “Critical Success!”)

>Else

>>If rand>90

>>>Then (Eval willcheck=0) (Say “Critical Failure!”)

>>>Else

>>>>If rand>will

>>>>>Then (Eval willcheck=0)

>>>>>Else (Eval willcheck=1)


I apologize for the terrible formatting but it was hard to represent the nested if/thens in the forum formatting.
Thamrill
Explorer At Heart
Explorer At Heart
Posts: 265
Joined: Thu Jan 03, 2013 4:55 pm
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [EOS] creating a subroutine

Post by Thamrill »

ritewriter wrote: Sun Jul 23, 2023 7:31 am Hey, does anyone know if there’s a way to create a callable subroutine that will run a series of commands. Something I can create in init then call with an eval?

I’m trying to have something that will run this when triggered:

Eval
rand=Math.floor(Math.random() * (100 - 1 + 1)) + 1;

If rand<11

>Then (Eval willcheck=) (Say “Critical Success!”)

>Else

>>If rand>90

>>>Then (Eval willcheck=0) (Say “Critical Failure!”)

>>>Else

>>>>If rand>will

>>>>>Then (Eval willcheck=0)

>>>>>Else (Eval willcheck=1)


I apologize for the terrible formatting but it was hard to represent the nested if/thens in the forum formatting.
If you need to post code, you can use the code display (</> button between quotes and list). In the initialization script write:

Code: Select all

text="";
willCheck=0;

function willCheckFunction(){
  rand=Math.floor(Math.random() * (100 - 1 + 1)) + 1;
  text="";
  willcheck=0;
  if(rand<11){
    text="Critical Success!";
    willcheck=1; //I guess, it's missing in you code
  }else if(rand>90){
    text="Critical Failure!";
    willcheck=0; 
  }else if(rand>will){
    willcheck=0;
    // text="Failure!"; Read comment below
  }else{
    willcheck=1;
    // text="Success!"; Read comment below
  }
}
To use this, in an Eval action set the script to willCheckFunction(); follow it with a Say action with the eval tag wrapping the text variable, if you want to say the text. This will be played even if there is no text, so it may be better to place a text for all4 possible outcomes (remove the "//" in front of the two comments I added above, which set the text)
Image

Image

Image
User avatar
ritewriter
Explorer At Heart
Explorer At Heart
Posts: 326
Joined: Sun Jan 02, 2022 6:51 am
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Switch
Contact:

Re: [EOS] creating a subroutine

Post by ritewriter »

Thank you! You're my hero.

I'm rethinking the dialogue inside the function and I think I'll replace it with a variable. Does this look right:

Code: Select all

critfail=0;
critwin=0;
willCheck=0;
rand=0;

function willCheckFunction(){
  rand=0;
  rand=Math.floor(Math.random() * (100 - 1 + 1)) + 1;
  critfail=0;
  critwin=0;
  willcheck=0;
  if(rand<11){
    critwin=1;
    willcheck=1; 
  }else if(rand>90){
    critfail=1;
    willcheck=0; 
  }else if(rand>will){
    willcheck=0;
  }else{
    willcheck=1;
  }
}
UPDATE: Tested and it, had an issue where rand seemed to carry over from previous checks (but might've been another issue) added the rand=0 initializer to the function (but also fiddled with the followup if/then which might've been the problem.

Now it works like a charm.

Thanks again and please let me know if anything looks wonky.
User avatar
ritewriter
Explorer At Heart
Explorer At Heart
Posts: 326
Joined: Sun Jan 02, 2022 6:51 am
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Switch
Contact:

Re: [EOS] creating a subroutine

Post by ritewriter »

I also tried to create a function for will loss and it tested properly. Does this look right?

Code: Select all

function willLoss(){
  rand=0;
  rand=Math.floor(Math.random() * (6 - 1 + 1)) + 1;
  willmin=0;
  if(will>10){
    will=will-rand; 
  }else{
    willmin=1;
  }
}
Thanks again!
Thamrill
Explorer At Heart
Explorer At Heart
Posts: 265
Joined: Thu Jan 03, 2013 4:55 pm
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [EOS] creating a subroutine

Post by Thamrill »

ritewriter wrote: Sun Jul 23, 2023 7:46 pm I also tried to create a function for will loss and it tested properly. Does this look right?

Code: Select all

function willLoss(){
  rand=0;
  rand=Math.floor(Math.random() * (6 - 1 + 1)) + 1;
  willmin=0;
  if(will>10){
    will=will-rand; 
  }else{
    willmin=1;
  }
}
Thanks again!
I don't know what it's supposed to do, so it's difficult to say if it's correct or not.

Right now what it does is:
- if the will is above ten, it reduces it by a number between 1 and 6; the minimum is 0;
- if it is 10 or less, it sets the minimum to 1 but leaves the will at the same value

If this is what it's supposed to do, then it is correct, otherwise, no
Image

Image

Image
User avatar
ritewriter
Explorer At Heart
Explorer At Heart
Posts: 326
Joined: Sun Jan 02, 2022 6:51 am
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Switch
Contact:

Re: [EOS] creating a subroutine

Post by ritewriter »

Thamrill wrote: Mon Jul 24, 2023 9:59 am
Right now what it does is:
- if the will is above ten, it reduces it by a number between 1 and 6; the minimum is 0;
- if it is 10 or less, it sets the minimum to 1 but leaves the will at the same value

If this is what it's supposed to do, then it is correct, otherwise, no
willmin is a flag that will is at or below minimum, so yep, looks like I got it right. By which I mean I just copied and pasted your code, then, by some miracle, modified it without managing to screw it up. It definitely seems to be working as intended.

Thank you again for everything!
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests