>>499
I thought the comments were fairly descriptive, but I'll try to explain
this is we start with, right?
$('input[name="email"]').val().split(/[^\d]/)
let me break it down
$('input[name="email"]')
is a jQuery selector for the email field, so
$('input[name="email"]').val()
gets the value of whatever is in the email field
once we have the whatever was typed in the email field, we split it using
$('input[name="email"]').val().split(/[^\d]/)
/[^\d]/
is a regular expression that means anything that is NOT a digit, like d, or +
.split() puts things in to an array, so you have to use [0], [1], [2], etc to select something from it
'1d20'.split(/[^\d]/)
Array [ "1", "20" ]
'1d20'.split(/[^\d]/)[0]
"1"
'1d20'.split(/[^\d]/)[1]
"20"
'4d6+5'.split(/[^\d]/)
Array [ "4", "6", "5" ]
'4d6+5'.split(/[^\d]/)[0]
"4"
'4d6+5'.split(/[^\d]/)[1]
"6"
'4d6+5'.split(/[^\d]/)[2]
"5"
.val() can be used to get a value, but it can also be used to change a value
so:
$('.dx').val($('input[name="email"]').val().split(/[^\d]/)[0]);
changes the value of dx, the dice field under [▶ Show post options & limits], to whatever the first number is
while
$('.dy').val($('input[name="email"]').val().split(/[^\d]/)[1]);
changes the value of dy, the sides field [▶ Show post options & limits], to whatever the second number is
and
$
('.dz').val($('input[name="email"]').val().split(/[^\d]/)[2]);
changes the value of dz, the modifier field under [▶ Show post options & limits], to whatever the third number is
if there is no number, which is the case with
'1d20'.split(/[^\d]/)[2]
undefined
then it just returns undefined, so when the value of the modifier field is changed, it leaves it blank