Oni Central Forum

A forum for the Oni community

You are not logged in.

#1 11/12/08 18:58

ItemfinderDeluxe
Member
From: Canberra, Australia
Registered: 12/11/07

Creating a random number generator?

Yeah, I don't know if it's possible, but can Oni have a function that generates a random number? Say, I have 10 strings of functions, each spawning a single guy in one spot. Each is assigned a number between 1 and 10, and a random number generator spits out a number that corresponds to a function. That single function is then executed. I know OTA has a proverbial generator, but that's just a series of loops that cycle to control spawns, stages, item generators, etc. I'm trying to work on something that really produces random numbers here.


TCTF SWAT: Striker, you're under arrest.
Striker: H4h, y0u c4n'7 570p m3!!!
TCTF SWAT: Damn it, learn to spell!!!
CURRENT PROJECT - 'Nemesis' V1.0 Released

Offline

#2 11/12/08 19:00

Gumby
Member
From: Seattle, WA, USA
Registered: 30/8/07

Re: Creating a random number generator?

No, not really sad

You can sort of copy OTA with a function like this:

var int max = 10;
var int number = 1;
func void rng(void) {
number = number + 1;
if (number>max) number = 1
fork rng
}

That should give you a semirandom number.


Iritscen: roll
Iritscen: it's amazing this program even works
Gumby: i know
Iritscen: and that statement applies to my code, not just yours

Offline

#3 11/12/08 19:49

Iritscen
Moderator
From: NC, USA
Registered: 22/10/07

Re: Creating a random number generator?

Well, there's two general ways to simulate randomness that I think are better than simply looping a number.  I mean, if we were going to just cycle values we might as well at least set up a series of, say, 10 conditionals like:

if (z eq 1)
x = 4
if (z eq 2)
x = 19
...

Where z is cycling from 1-10, and where the fixed values for x came from a random number generator.  That would at least give a "random" series of numbers, albeit the same series each time for lack of a random seed.

A truer, but still simulated, generator of random numbers would have to work in one of two ways that I can think of: watching for an event, or reading a value through BSL that had initially been set randomly, such as properties of some particles, and character heights/skins.  It seems that our ability to read those kinds of values is severely limited (I can't find any values accessible through scripting that are set randomly).

So that leaves the first option, waiting for an event.  You could use chr_wait_animation to wait for a series of animations, for instance, incrementing or decrementing a variable by some differing number for each animation that you think might be used:

var int x = 0;

func void main (void)
{
   fork animWatch
   [...]
}

func animWatch
{
   fork punchWatch
   fork kickWatch
   [...]
}

func punchWatch
{
   chr_wait_animation 0 KONCOMcomb_p
   x = x + 5
   sleep 600
}

func kickWatch
{
   chr_wait_animation 0 KONCOMcomb_k
   x = x - 3
   sleep 600
}

That should give an effectively random number, no?


byproducts are fine, but where's the beef?

Offline

Board footer

Powered by FluxBB