Randomizing..

A refuge for those migrating from the fallen DXEditing.com and a place for general discussion relating to Deus Ex editing (coding, mapping, etc).
Post Reply
~DJ~
UNATCO
Posts: 277
Joined: Thu Sep 13, 2007 4:15 pm

Randomizing..

Post by ~DJ~ »

Hey there.

I want to randomize stuff in UScript, let's just say I succeeded at that...

But here's a problem.


See, I am using fRand, and I've put inputs till 19, Like if(fRand<0.19) (and so on) and all. Problem is now, I want it that if it reaches above 0.19, I want it to reset randomly and don't exceed above 0.19.. How can that be possible?


Thanks guise!
DDL
Traditional Evil Scientist
Traditional Evil Scientist
Posts: 3791
Joined: Mon Oct 17, 2005 10:03 am

Re: Randomizing..

Post by DDL »

so..wait, you want to choose between 19 different things?

And you're doing it like

Code: Select all

rnd = frand();
if(rnd < 0.01)
something();
else if(rnd < 0.02)
somethingelse();
else if(rnd < 0.03)
yetanotherthing();
...etc
this? Up to 0.19? And if frand gives a value above 0.19 you want it to have another go until it's below 0.19?

If I'm reading this correctly, then this is a bad way of doing it. At the very least you could simply make it 20 things and have the thresholds in increments of 0.05, or use increments of 0.052631578947368421052631578947368 (or 0.0526 or similar), which is 1/19.

Something like

Code: Select all

rnd = frand()/0.0526;
if(rnd < 1)
something();
else if(rnd < 2)
somethingelse();
...etc
but even then, it's a bit laborious: if you want to choose between 19 random things, you could just use rand(19), which will pick a random integer between 0 and 18.

You could even use a switch statement, or hold variables in a defprops array or something.

But yeah, bit more info might be nice.
~DJ~
UNATCO
Posts: 277
Joined: Thu Sep 13, 2007 4:15 pm

Re: Randomizing..

Post by ~DJ~ »

DDL wrote:so..wait, you want to choose between 19 different things?

And you're doing it like

Code: Select all

rnd = frand();
if(rnd < 0.01)
something();
else if(rnd < 0.02)
somethingelse();
else if(rnd < 0.03)
yetanotherthing();
...etc
this? Up to 0.19? And if frand gives a value above 0.19 you want it to have another go until it's below 0.19?
Exactly that.

Alright, more info, and I'll make em 20.

So, I'll tell a bit about what I am trying to do, let's say;

There's this model and I want it to have 20 different textures randomly when it spawns, and I've done a code at PostBeginPlay, everything's fine except that when it reaches above 0.19, it goes to the default properties one which I haven't configured till there. So you see?
DDL
Traditional Evil Scientist
Traditional Evil Scientist
Posts: 3791
Joined: Mon Oct 17, 2005 10:03 am

Re: Randomizing..

Post by DDL »

Ok, I'm assuming you mean "one of twenty possible textures", since no model in the unreal engine DX is based on can have more than 8 (arguably 9) different textures at one time... :D

In that case, why not do this:

Code: Select all

class myclass extends whatever;

var texture swaptex[19];


function postbeginplay()
{
     super.postbeginplay();
     multiskins[0] = swaptex[rand(19)];
}

defaultproperties
{
swaptex(0)=texture'mypackage.mytex1'
swaptex(1)=texture'mypackage.mytex2'
swaptex(2)=texture'mypackage.mytex3'

...etc

So that it simply reskins on startup from one of 19 possible textures specified in defprops.
~DJ~
UNATCO
Posts: 277
Joined: Thu Sep 13, 2007 4:15 pm

Re: Randomizing..

Post by ~DJ~ »

Thanks for your help!

I'll try different stuff and combined stuff. yeah.
Post Reply