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!
Randomizing..
Re: Randomizing..
so..wait, you want to choose between 19 different things?
And you're doing it like
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
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.
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
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
You could even use a switch statement, or hold variables in a defprops array or something.
But yeah, bit more info might be nice.
Re: Randomizing..
Exactly that.DDL wrote:so..wait, you want to choose between 19 different things?
And you're doing it like
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?Code: Select all
rnd = frand(); if(rnd < 0.01) something(); else if(rnd < 0.02) somethingelse(); else if(rnd < 0.03) yetanotherthing(); ...etc
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?
Re: Randomizing..
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...
In that case, why not do this:
So that it simply reskins on startup from one of 19 possible textures specified in defprops.
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
Re: Randomizing..
Thanks for your help!
I'll try different stuff and combined stuff. yeah.
I'll try different stuff and combined stuff. yeah.