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.
[EOS] creating a subroutine
- ritewriter
- Explorer At Heart

- Posts: 454
- Joined: Sun Jan 02, 2022 6:51 am
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Switch
-
Thamrill
- Explorer At Heart

- Posts: 301
- Joined: Thu Jan 03, 2013 4:55 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Re: [EOS] creating a subroutine
If you need to post code, you can use the code display (</> button between quotes and list). In the initialization script write: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.
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
}
}
- ritewriter
- Explorer At Heart

- Posts: 454
- Joined: Sun Jan 02, 2022 6:51 am
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Switch
Re: [EOS] creating a subroutine
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:
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.
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;
}
}
Now it works like a charm.
Thanks again and please let me know if anything looks wonky.
- ritewriter
- Explorer At Heart

- Posts: 454
- Joined: Sun Jan 02, 2022 6:51 am
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Switch
Re: [EOS] creating a subroutine
I also tried to create a function for will loss and it tested properly. Does this look right?
Thanks again!
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;
}
}
-
Thamrill
- Explorer At Heart

- Posts: 301
- Joined: Thu Jan 03, 2013 4:55 pm
- Gender: Male
- Sexual Orientation: Straight
- I am a: Submissive
Re: [EOS] creating a subroutine
I don't know what it's supposed to do, so it's difficult to say if it's correct or not.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?
Thanks again!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; } }
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
- ritewriter
- Explorer At Heart

- Posts: 454
- Joined: Sun Jan 02, 2022 6:51 am
- Gender: Male
- Sexual Orientation: Open to new ideas!
- I am a: Switch
Re: [EOS] creating a subroutine
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.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
Thank you again for everything!
