Duke4.net Forums: How exactly "ifrnd" command works? - Duke4.net Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How exactly "ifrnd" command works?

User is offline   Fox 

  • Fraka kaka kaka kaka-kow!

#1

This is an example of code used in GAME.CON:

  ifrnd 64
  {
    ifnosounds
      soundonce TOUGHGALSND1
  }
  else
    ifrnd 64
  {
    ifnosounds
      soundonce TOUGHGALSND2
  }
  else
    ifrnd 64
  {
    ifnosounds
      soundonce TOUGHGALSND3
  }
  else
    ifnosounds
      soundonce TOUGHGALSND4


This makes me raise the question of how exactly "ifrnd" used in conjunction with "else" works.

In the example below, if I subtract the chances of each "ifrnd" based on the last one, I would have this result:
- 1st sound: 25% of chances
- 2nd sound: 18% of chances
- 3rd sound: 14% of chances
- 4th sound: 42% of chances

Or was this code meant to provide equal chances of 25% for each sound?
0

User is online   Danukem 

  • Duke Plus Developer

#2

Your analysis of the percentages is correct, except that the last only plays "ifnosounds".

ifrnd works like any other if condition.

If you wanted there to be 25% chance per sound, you would structure it like this:

ifrnd 128 { ifrnd 128 sound ONE else sound TWO } else { ifrnd 128 sound THREE else sound FOUR }
1

#3

If you don't want to use the ifrnd command you can use the randvar command.
0

User is offline   Jimmy 

  • Let's go Brandon!

#4

That's what I do now. I really don't trust the ifrnd command, and ultimately it gives you less control in some situations where vars are needed.
0

User is offline   Zaxtor 

#5

ifrnd I think is a randomlized delayer.

Ifcount 100 with ifrnd 50 { blah blah blah }

Will make ifcount goes 100 (as normal) or makes it go 100 2x times. Like 200.
Is a randomlizing thing.

Not sure.
0

User is offline   Mblackwell 

  • Evil Overlord

#6

View PostCaptain Awesome, on 28 August 2011 - 03:41 PM, said:

That's what I do now. I really don't trust the ifrnd command, and ultimately it gives you less control in some situations where vars are needed.


I use it for quick randomizations that I don't care much about (changing enemy states, etc). Otherwise it's off to randvar land. Particularly if it's part of a clever formula.
0

#7

View PostZaxtor, on 28 August 2011 - 07:53 PM, said:

ifrnd I think is a randomlized delayer.

Ifcount 100 with ifrnd 50 { blah blah blah }

Will make ifcount goes 100 (as normal) or makes it go 100 2x times. Like 200.
Is a randomlizing thing.

Not sure.


I suggest that you read the ifrnd page on eduke wiki. And then all the posts in here. :(

This post has been edited by rasmus thorup: 29 August 2011 - 09:54 AM

0

User is offline   Zaxtor 

#8

:( ok.

rnd is symbole for RaNDom
0

#9

Are you serious?
0

User is offline   Zaxtor 

#10

Looked for its meaning

ifrnd <value> { do something } else { do something else }
An if condition stating the probability of it 'doin somethin!' in this case.
NOTE: It's out of 256 as max, so 'ifrnd 256 = 100%', and 'ifrnd 128 = 50%'
This command must only be used in synchronised code or you will cause desyncs. for display code use displayrand instead.


I mean its usage without else.

Like ifcount xxx ifrnd xxx { your sprite's behavior }.

I used like that and it sorta acts randomly.

256 (100%) = 128 (50%)
So I guess is the chance it will act. if fails it reset until it succeed.
I think.

This post has been edited by Zaxtor: 29 August 2011 - 02:42 PM

0

User is offline   Mblackwell 

  • Evil Overlord

#11

Keep in mind that it runs every game tic too. So every time it's looking through your actor code it's checking if it should change. So ifrnd 128 without any other conditions means it has a 50% chance of happening 30 times in a single second.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


All copyrights and trademarks not owned by Voidpoint, LLC are the sole property of their respective owners. Play Ion Fury! ;) © Voidpoint, LLC

Enter your sign in name and password


Sign in options