Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

random spell on scroll generator non functioning

January 07 (4 years ago)

on('ready', () => 

{

const die = (sides) => randomInteger(sides);

var LivelloPergamena = die(6);

var IncantesimiLivello1Chierico = die(8)

var IncantesimiLivello2Chierico = die(3)

var IncantesimiLivello1Mago = die(12)

var IncantesimiLivello2Mago = die(12)

var IncantesimiLivello3Mago = die(3)

var TipoPergamena = die(4);

on('chat:message', (msg) => 

    {

    if ('api' === msg.type && msg.content.match(/^!Pergamena3/)) 

        {

            




        if (TipoPergamena = 1) 

            {

            var PergamenaChierico = 3

            for (PergamenaChierico; PergamenaChierico > 0; PergamenaChierico --)

                {

                if (LivelloPergamena >0 && LivelloPergamena <5)

                    { 

                    if (IncantesimiLivello1Chierico = 1)

                    {

        sendChat('Incantesimo clericale', `/w gm Cura ferite leggere`);

        }

                    else if (IncantesimiLivello1Chierico = 2)

                    {

        sendChat('Incantesimo clericale', `/w gm Individuazione del magico`);

        }

                    else if (IncantesimiLivello1Chierico = 3)

                    {

        sendChat('Incantesimo clericale', `/w gm Individuazione del male`);

        }

                    else if (IncantesimiLivello1Chierico = 4)

                    {

        sendChat('Incantesimo clericale', `/w gm Luce Magica`);

        }

                    else if (IncantesimiLivello1Chierico = 5)

                    {

        sendChat('Incantesimo clericale', `/w gm Protezione dal male`);

        }

                    else if (IncantesimiLivello1Chierico =6)

                    {

        sendChat('Incantesimo clericale', `/w gm Resistenza al freddo`);

        }

                    else if (IncantesimiLivello1Chierico =7)

                    {

        sendChat('Incantesimo clericale', `/w gm Purificazione dei cibi e dell’acqua`);

        }

                    else if (IncantesimiLivello1Chierico =8)

                    {

        sendChat('Incantesimo clericale', `/w gm Scacciapaura`);

        }

        }

                else if (LivelloPergamena >4)

                {

                    if (IncantesimiLivello2Chierico = 1)

                    {

        sendChat('Incantesimo clericale', `/w gm Benedizione`);

        }

                    else if (IncantesimiLivello2Chierico = 2)

                    {

        sendChat('Incantesimo clericale', `/w gm Blocca-persona`);

        }

                    else if (IncantesimiLivello2Chierico = 3)

                    {

        sendChat('Incantesimo clericale', `/w gm Silenzio nel raggio di 5 metri`);

        }

            }

            }

            }

        else if (TipoPergamena >1)

        {

        var PergamenaMago = 3

            for (PergamenaMago; PergamenaMago > 0; PergamenaMago --)

                {

                if (LivelloPergamena >0 && LivelloPergamena <4)

        {

                    if (IncantesimiLivello1Mago = 1)

                    {

        sendChat('Incantesimo mago', `/w gm Blocca porta`);

        }

                    else if (IncantesimiLivello1Mago = 2)

                    {

        sendChat('Incantesimo mago', `/w gm Dardo incantato`);

        }

                    else if (IncantesimiLivello1Mago = 3)

                    {

        sendChat('Incantesimo mago', `/w gm Disco levitante`);

        }

                    else if (IncantesimiLivello1Mago = 4)

                    {

        sendChat('Incantesimo mago', `/w gm Lettura dei linguaggi`);

        }

                    else if (IncantesimiLivello1Mago = 5)

                    {

        sendChat('Incantesimo mago', `/w gm Lettura del magico`);

        }

                    else if (IncantesimiLivello1Mago =6)

                    {

        sendChat('Incantesimo mago', `/w gm Luce magica`);

        }

                    else if (IncantesimiLivello1Mago =7)

                    {

        sendChat('Incantesimo mago', `/w gm Incantesimo dello charme`);

        }

                    else if (IncantesimiLivello1Mago =8)

                    {

        sendChat('Incantesimo mago', `/w gm Incantesimo del sonno`);

        }

                    else if (IncantesimiLivello1Mago = 9)

                    {

        sendChat('Incantesimo mago', `/w gm Individuazione del magico`);

        }

                    else if (IncantesimiLivello1Mago =10)

                    {

        sendChat('Incantesimo mago', `/w gm Protezione dal male`);

        }

                    else if (IncantesimiLivello1Mago =11)

                    {

        sendChat('Incantesimo mago', `/w gm Scudo magico`);

        }

                    else if (IncantesimiLivello1Mago =12)

                    {

        sendChat('Incantesimo mago', `/w gm Ventriloquio`);

        }

        }

                else if (LivelloPergamena >3 && LivelloPergamena <6)

                    {

                    if (IncantesimiLivello2Mago = 1)

                    {

        sendChat('Incantesimo mago', `/w gm Chiavistello magico`);

        }

                    else if (IncantesimiLivello2Mago = 2)

                    {

        sendChat('Incantesimo mago', `/w gm Creazione spettrale`);

        }

                    else if (IncantesimiLivello2Mago = 3)

                    {

        sendChat('Incantesimo mago', `/w gm E.S.P.`);

        }

                    else if (IncantesimiLivello2Mago = 4)

                    {

        sendChat('Incantesimo mago', `/w gm Levitazione`);

        }

                    else if (IncantesimiLivello2Mago = 5)

                    {

        sendChat('Incantesimo mago', `/w gm Luce perenne`);

        }

                    else if (IncantesimiLivello2Mago =6)

                    {

        sendChat('Incantesimo mago', `/w gm Individuazione del male`);

        }

                    else if (IncantesimiLivello2Mago =7)

                    {

        sendChat('Incantesimo mago', `/w gm Immagini illusorie`);

        }

                    else if (IncantesimiLivello2Mago =8)

                    {

        sendChat('Incantesimo mago', `/w gm Individuazione dell’invisibile`);

        }

                    else if (IncantesimiLivello2Mago = 9)

                    {

        sendChat('Incantesimo mago', `/w gm Individuazione di un oggetto`);

        }

                    else if (IncantesimiLivello2Mago =10)

                    {

        sendChat('Incantesimo mago', `/w gm Invisibilità`);

        }

                    else if (IncantesimiLivello2Mago =11)

                    {

        sendChat('Incantesimo mago', `/w gm Ragnatela`);

        }

                    else if (IncantesimiLivello2Mago =12)

                    {

        sendChat('Incantesimo mago', `/w gm Scassinare`);

        }

        }

                else if (LivelloPergamena =6)

                    {

                    if (IncantesimiLivello3Mago = 1)

                    {

        sendChat('Incantesimo mago', `/w gm Dispersione del magico`);

        }

                    else if (IncantesimiLivello3Mago = 2)

                    {

        sendChat('Incantesimo mago', `/w gm Palla di fuoco`);

        }

                    else if (IncantesimiLivello3Mago = 3)

                    {

        sendChat('Incantesimo mago', `/w gm Volo`);

        }

        }

        }

        }

        }

    })

})

This API return ever ever:
(From Incantesimo clericale): Cura ferite leggere
(From Incantesimo clericale): Cura ferite leggere
(From Incantesimo clericale): Cura ferite leggere
But the result that i want is a random generator of 3 spells on scroll that are to be various... where i'm wrong?
Thanks for the help.







January 07 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

You are using =, which is assignment.  You should be using === which is comparision.

        else if (IncantesimiLivello3Mago = 3)

Says "Assign the value 3 to IncantesimiLivello3Mago, and then check if it's truthy (greater than zero)"

It (and other if blocks) like it should be:

        else if (IncantesimiLivello3Mago === 3)

Which says "Check if IncantesimiLivello3Mago is precisely the value 3, and if it is ..."


January 07 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Incidentally, if you write your tests with the literal value first, the parser will tell you there is an error instead of blindly accepting the code:

if( 3 = IncantesimiLivello3Mago)

Will result in "SyntaxError: Invalid left-hand side in assignment", thus pointing you at the error.

January 07 (4 years ago)

i've corrected = with === but script still not working.

It repeats ever 3 times the same thing.

January 07 (4 years ago)

Edited January 07 (4 years ago)

i thank you The Aaron, now the script works correctly ;)

January 08 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

Great!