Interactions SOMETIMES seems not to work at a random variable

Started by DiegoHolt, Sat 07/09/2024 04:00:26

Previous topic - Next topic

DiegoHolt

Hello fellow adventurer sages, I'm having the following issue:

Code: ags
               
    dialogoRandom = Random (3);
         if (dialogoRandom == 2)
    {
     player.Say("Parece una especie de ídolo");
     player.Say("Sea lo que sea, es horrible");
    }
         if (dialogoRandom == 1)
    {
     player.Say("Nunca entendí la función de estas cosas");
     player.Say("¿Son indicadores de algo?");
     player.Say("¿Son tumbas?");
     player.Say("¿Simple decoración?");
    }
         if (dialogoRandom == 0)
    {
     player.Say("Calor, ¿eh?");
     player.Say("Pero ya debes estar acostumbrado");
     Wait(33);
     player.FaceDirection(eDirectionDown);
     player.Say("No, no estoy hablando solo");
     player.Say("¿Con quién crees que hablo AHORA?");
    }

That's my attempt to add multiple and random answers at an interaction, but the thing is that sometimes none of the dialogs is displayed and it looks to the player like no action has ocurred. What am I missing here?

Thanks in advance for all of your wisdom  :-D

Crimson Wizard

Quote from: DiegoHolt on Sat 07/09/2024 04:00:26That's my attempt to add multiple and random answers at an interaction, but the thing is that sometimes none of the dialogs is displayed and it looks to the player like no action has ocurred. What am I missing here?

Random(N) function returns any number from 0 to N inclusive. You call Random(3), it may return 0,1,2,3.
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#random

eri0o

A simple way to spot this would be to print that value to the log

Code: ags
System.Log(eLogInfo, "dialogoRandom: %d", dialogoRandom);

DiegoHolt


[/quote]

Random(N) function returns any number from 0 to N inclusive. You call Random(3), it may return 0,1,2,3.
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#random
[/quote]

Yep, that was it!

I don't know why I thought that the random number included the 0 when counting...

Thanks a lot! To both of you, eriOo your code will be useful to me as well!

eri0o

Cool :)

Also the forums use a thing called BBCode for the messages which uses tags, which can be interpreted differently depending on exact forum implementation, but the gist is the following

Code: txt
A tag uses a pair of "[" and "]" characters to contain some content inside (usually the first part is the "tag name"

A tag that modifies text is paired with another with same name and a "/" character before "tag name", usually referred as closing tag.

So something like [tagname]some text[/tagname]

This is why your quote usage didn't work, you used a pair of closing quote tags so the forums can't parse and understand where the text that you want to mark as quote began and ended. It should be something like:

Code: ags
[quote]a text that is a quote[/quote]

Khris

Quote from: DiegoHolt on Sat 07/09/2024 19:42:45I don't know why I thought that the random number included the 0 when counting...
???

Sorry, just to clarify: the result range does include 0, and more importantly: does include the integer you pass, which was the reason your code failed every fourth time on average.

DiegoHolt

Hi, Khris! I'm sorry, what I meant to say was that I was thinking that in the total numbers of the random integer (for example, 4) it only counted a total of FOUR, including the 0. (0,1,2,3 and that was my mistake)

Anyway, big thanks to all of you that are always there willing to help!  :)

Snarky

Quote from: DiegoHolt on Mon 09/09/2024 01:21:02Hi, Khris! I'm sorry, what I meant to say was that I was thinking that in the total numbers of the random integer (for example, 4) it only counted a total of FOUR, including the 0. (0,1,2,3 and that was my mistake)

That is a very reasonable assumption, and as I have argued previously, I feel that the fact that it doesn't work like that is a mistake in the AGS API.

SMF spam blocked by CleanTalk