Pocket Plane Group

Miscellany, Inc. => Infinity Engine Modding Q&A => Topic started by: Baldurien on July 25, 2004, 02:56:04 PM

Title: What do multiple call of RandomNum ?
Post by: Baldurien on July 25, 2004, 02:56:04 PM
Continuing my quest to the "perfect multiplayer dialog", I have a new question about RandomNum.

This function give a Random number between 0 and Range, and test if value match.

What I would like to know, is about multiple calls :

Code: [Select]
IF RandomNum(9,0) THEN 0 END
IF RandomNum(9,1) THEN 1 END
IF RandomNum(9,2) THEN 2 END
IF RandomNum(9,3) THEN 3 END
IF True() THEN 4 END

As a C programmer, I would say that RandomNum will be reevaluated each time, so considering each time we have 10 possible choices and only one that good :

We have 0.1 chances to go in the first statement (0)
We have 0.9*0.1 chances to go the second statement (1)
We have 0.9*0.9*0.1 chances to go the third statement (2)
We have 0.9*0.9*0.9*0.1 chances to go the fourth statement (3)
And 0.9*0.9*0.9*0.9 chances for the True statement

The chances are 10% / 9% / 8.1% / 7.29% / 65,61% (if I'm not wrong with my maths;))

As you can see it there are a big chance for the True statement to be choosen (I assume that I added a fifth statement I would have been around 55%)

That is only if RandomNum pick up a random Int each time it is called.

Now I would like to know : How to have an equal probability for the four statement (ie: 10% each) without doing maths ? (ie: I use a trick)

For the moment, my dialog plus the condition i used always resume in the default choice, and that is particuliary ... annoying.

[edit] If I read http://www.gibberlings3.net/iesdp/scripting/bg2triggers.htm I see that RandomNum give a number between 1 and Range, and 0 and Range in the Scripting Quick Ref (in script compiler of nwn) ... ?
     
Title: Re: What do multiple call of RandomNum ?
Post by: jcompton on July 25, 2004, 07:04:53 PM

Code: [Select]
IF RandomNum(9,0) THEN 0 END
IF RandomNum(9,1) THEN 1 END
IF RandomNum(9,2) THEN 2 END
IF RandomNum(9,3) THEN 3 END
IF True() THEN 4 END

As a C programmer, I would say that RandomNum will be reevaluated each time, so considering each time we have 10 possible choices and only one that good :

No, it won't be. It's evaluated once in the trigger block, at least only once per seed value.

However, the most IMPORTANT thing you need to know here is that... well, this isn't valid code anyway because you haven't specified GOTO or EXTERN or encapsulated the triggers in ~~, but also that transitions are evaluated BOTTOM-UP. So the engine will stop at True(). You want to put True() at the top of the stack, not the bottom.
Title: Re: What do multiple call of RandomNum ?
Post by: Baldurien on July 26, 2004, 03:41:20 AM
Hem, that was a script, not a *.D file. (I was to lazy to use RESPONSE #100)
Title: Re: What do multiple call of RandomNum ?
Post by: Baldurien on July 26, 2004, 05:50:01 PM
Hum

I understood that transition are analysed from bottom to top, is that the same with the state?
Title: Re: What do multiple call of RandomNum ?
Post by: SimDing0™ on July 26, 2004, 05:53:35 PM
No, states are evaluated top-down.
Title: Re: What do multiple call of RandomNum ?
Post by: jcompton on July 26, 2004, 05:53:58 PM
I'm actually not sure how script triggers are evaluated. State triggers are evaluated by WEIGHT order, which by default is top-down.
Title: Re: What do multiple call of RandomNum ?
Post by: SimDing0™ on July 26, 2004, 06:01:04 PM
Script blocks are also top-down, and within each block the triggers are top-down too.
Title: Re: What do multiple call of RandomNum ?
Post by: Baldurien on July 26, 2004, 06:16:13 PM
Okidoki.

Hum now, if I've got that :
Code: [Select]
IF ~~ THEN BEGIN stateLabel
  SAY ~blah~
  IF ~~ THEN EXIT
END

That state will always appears right ? What should I do :
1. Put each inner state at end of file (before INTERJECT, APPEND, and so..) and add a default dialog as root child (... hem, in Infinity Explorer, I would be the node we see without clicking on the square)
2. Use LOCALS to avoid that we see the dialogue such as :

Code: [Select]
IF ~Global("Foo", "LOCALS", 1)~ THEN BEGIN stateLabel
  SAY ~blah~
  IF ~~ THEN EXIT
END

?
Title: Re: What do multiple call of RandomNum ?
Post by: jcompton on July 26, 2004, 08:09:24 PM
Okidoki.

Hum now, if I've got that :
Code: [Select]
IF ~~ THEN BEGIN stateLabel
  SAY ~blah~
  IF ~~ THEN EXIT
END

That state will always appears right ? What should I do :

No, that state will NEVER appear unless you directly GOTO/EXTERN to it, because its state trigger is empty, which for state triggers is considered to be False().
Title: Re: What do multiple call of RandomNum ?
Post by: Baldurien on July 27, 2004, 03:45:53 AM
Ok, that work for me :)

Bioware DLG file (and D file) are pretty simple finally. Even if I think that would be cool to have an editor like the one NWN provide;)