Home   Help Search Login Register  

Author Topic: Random Fuction giving me grief  (Read 1132 times)

0 Members and 1 Guest are viewing this topic.

PBrain

  • Guest
Random Fuction giving me grief
« on: 11 Aug 2006, 05:31:46 »
In my mission I have six guys. A random number of them are supposed to be chosen as casualties along the way for you to encounter. It is done by assigning each guy a random number (between 0 and 1) and if that number is greater and .5, they are chosen to be casualties and put in their place. Unfortunately, it is not working because only one guy has ever been a casualty at any one time (and its only ever rifleman1 or rifleman2) in my 10 tests so any suggestions on my script would be greatly appreciated. Thanks!

Quote
_rifleman1number = random(1); assigning each guy his number
_rifleman2number = random(1)
_rifleman3number = random(1)
_rifleman4number = random(1)
_machinegunner1number = random(1)
_ATriflemannumber = random(1)

#checker
?(_rifleman1number > .5): goto "rifleman1dead" ;checking to see if they are chosen to be a casualty
?(_rifleman2number > .5): goto "rifleman2dead"
?(_rifleman3number > .5): goto "rifleman3dead"
?(_rifleman4number > .5): goto "rifleman4dead"
?(_machinegunnernumber > .5): goto "machinegunnerdead"
?(_ATriflemannumber > .5): goto "ATriflemandead"
exit

#rifleman1dead ;the part that makes them a casualty (killing them and putting them in a fixed location)
~.01
rifleman1 setpos (getpos rifleman1dead)
rifleman1 setdamage 1
_rifleman1dead = 0 ;set its number to 0 so it doesn't keep checking the same guy
goto "checker" ;go back to checking others

#rifleman2dead
~.01
rifleman2 setpos (getpos rifleman2dead)
rifleman2 setdamage 1
_rifleman2dead = 0
goto "checker"

#rifleman3dead
~.01
rifleman3 setpos (getpos rifleman3dead)
rifleman3 setdamage 1
_rifleman3dead = 0
goto "checker"

#rifleman4dead
~.01
rifleman4 setpos (getpos rifleman4dead)
rifleman4 setdamage 1
_rifleman4dead = 0
goto "checker"

#machinegunnerdead
~.01
machinegunner setpos (getpos machinegunnerdead)
machinegunner setdamage 1
_machinegunnerdead = 0
goto "checker"

#ATriflemandead
~.01
ATrifleman setpos (getpos ATriflemandead)
ATrifleman setdamage 1
_ATriflemandead = 0
goto "checker"

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: Random Fuction giving me grief
« Reply #1 on: 11 Aug 2006, 05:51:38 »
I'm not sure whats causing your problem off hand, but why not try to increase the randomness to 10 and set the .5 value to 5.  I'm guessing here but I think that random(1) only gives you the random number between 0 and 1. I'd be very surprised if the random(1) ever turned up a .5 its either going to be 1 or 0.  So if you increase the random(1) to random 10 and then do your check on > 5 it may help.

Hoz
Xbox Rocks

Offline Razorwings18

  • Contributing Member
  • **
  • I'm NOT a llama. I checked.
Re: Random Fuction giving me grief
« Reply #2 on: 11 Aug 2006, 07:04:41 »
You need new glasses.

Check this line in your script:
_rifleman1dead = 0 ;set its number to 0 so it doesn't keep checking the same guy

Variable name is wrong. Should be:
_rifleman1number = 0

Cheers.
« Last Edit: 11 Aug 2006, 07:11:24 by Razorwings18 »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Random Fuction giving me grief
« Reply #3 on: 11 Aug 2006, 09:12:14 »
I'm guessing here but I think that random(1) only gives you the random number between 0 and 1. I'd be very surprised if the random(1) ever turned up a .5 its either going to be 1 or 0.  So if you increase the random(1) to random 10 and then do your check on > 5 it may help.
Random 1 gives you a random floating point value between 0.000000 and 1.000000...
So there's a lot more variation than just 1 or 0 there ;)

Quick tests gave me numers like 0.044678, 0.244576, 0.267896 and 0.763452 so basicly it should not really matter..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline hoz

  • OFPEC Site
  • Administrator
  • *****
Re: Random Fuction giving me grief
« Reply #4 on: 11 Aug 2006, 14:19:34 »
[
Random 1 gives you a random floating point value between 0.000000 and 1.000000...
So there's a lot more variation than just 1 or 0 there ;)

Quick tests gave me numers like 0.044678, 0.244576, 0.267896 and 0.763452 so basicly it should not really matter..

Learn something everyday ;)

Hoz
Xbox Rocks