Author Topic: What do multiple call of RandomNum ?  (Read 2436 times)

Offline Baldurien

  • Planewalker
  • *****
  • Posts: 28
What do multiple call of RandomNum ?
« 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) ... ?
     
« Last Edit: July 25, 2004, 03:20:37 PM by Baldurien »

Offline jcompton

  • Niche Exploiter
  • Administrator
  • Planewalker
  • *****
  • Posts: 7246
Re: What do multiple call of RandomNum ?
« Reply #1 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.
Cespenar says, "Kelsey and friends be at the Pocket Plane? Ohhh yesssss!" http://www.pocketplane.net

Offline Baldurien

  • Planewalker
  • *****
  • Posts: 28
Re: What do multiple call of RandomNum ?
« Reply #2 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)

Offline Baldurien

  • Planewalker
  • *****
  • Posts: 28
Re: What do multiple call of RandomNum ?
« Reply #3 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?

Offline SimDing0™

  • Back In Black
  • Global Moderator
  • Planewalker
  • *****
  • Posts: 3496
  • Gender: Male
  • Word Enhancer
Re: What do multiple call of RandomNum ?
« Reply #4 on: July 26, 2004, 05:53:35 PM »
No, states are evaluated top-down.

Offline jcompton

  • Niche Exploiter
  • Administrator
  • Planewalker
  • *****
  • Posts: 7246
Re: What do multiple call of RandomNum ?
« Reply #5 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.
Cespenar says, "Kelsey and friends be at the Pocket Plane? Ohhh yesssss!" http://www.pocketplane.net

Offline SimDing0™

  • Back In Black
  • Global Moderator
  • Planewalker
  • *****
  • Posts: 3496
  • Gender: Male
  • Word Enhancer
Re: What do multiple call of RandomNum ?
« Reply #6 on: July 26, 2004, 06:01:04 PM »
Script blocks are also top-down, and within each block the triggers are top-down too.

Offline Baldurien

  • Planewalker
  • *****
  • Posts: 28
Re: What do multiple call of RandomNum ?
« Reply #7 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

?
« Last Edit: July 26, 2004, 06:21:50 PM by Baldurien »

Offline jcompton

  • Niche Exploiter
  • Administrator
  • Planewalker
  • *****
  • Posts: 7246
Re: What do multiple call of RandomNum ?
« Reply #8 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().
Cespenar says, "Kelsey and friends be at the Pocket Plane? Ohhh yesssss!" http://www.pocketplane.net

Offline Baldurien

  • Planewalker
  • *****
  • Posts: 28
Re: What do multiple call of RandomNum ?
« Reply #9 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;)

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: