Oni Central Forum

A forum for the Oni community

You are not logged in.

#1 06/12/08 22:06

gmsly
Member
From: VY CMa
Registered: 05/17/08

The Random Number

How to make the Random Number.. i only need 1 2 3 4 ...

Like this:

func gmsly104
{
    if (sj eq 0)
    {
        ai2_spawn npc_1
                                ...
    }
    if (sj eq 1)
    {
        ai2_spawn npc_2
                                ...
    }
    if (sj eq 2)
    {
        ai2_spawn npc_3
                                ...
    }
    if (sj eq 3)
    {
        ai2_spawn npc_4
                                ...
    }
}

Offline

#2 06/12/08 23:06

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: The Random Number

Take a look at Oni Team Arena: http://wiki.oni2.net/OTA
One part of the script is called random.  Perhaps that can help you to generate a random number.

Offline

#3 06/12/08 23:06

gmsly
Member
From: VY CMa
Registered: 05/17/08

Re: The Random Number

Thanks ....now i will review my English and look at that

Offline

#4 06/13/08 18:06

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

Re: The Random Number

IIRC, it uses the number of frames since OTA was started. However, that has some flaws, such as multiple characters dieing at once given identical items.

If I ever were to improve OTA like I keep saying I will (not that OTA is mine in the beginning, it is geyser's, but I have permission to improve it tongue) I will improve that system.


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

#5 06/13/08 18:06

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: The Random Number

Gumby: Can you write a function that will produce random numbers within a certain range, that we can use?

Congrats on your graduation!

Offline

#6 06/13/08 18:06

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

Re: The Random Number

Thanks. Let me double check the OTA script to check that that is indeed how it works.
It will be up tomorrow, I have to leave now.

EDIT: Oh yuck. The current fuction is ugly. But it works. Basically it is a loop. I don't like it, but I can't do anything about it right now. It works well though. big_smile

func void RandGen(void) {
    rand_cell= rand_cell + 1; if(rand_cell > rand_cell_max) rand_cell= 0;
}

basically, rand_cell is your random number, rand_cell_max is the highest rand_cell can go.

It doesn't work too well if you need to call a whole bunch of the same type of  random thing at once.
If I were to make a random function, it would work a bit differently, but I have to go now!

Last edited by Gumby (06/13/08 19:06)


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

#7 06/13/08 23:06

coool
Member
From: China Haikou
Registered: 02/12/08

Re: The Random Number

func void RandGen(void) {
    rand_cell= rand_cell + 1; if(rand_cell > rand_cell_max) rand_cell= 0;
}

maybe we should add a "fork"? like

func void RandGen(void) {
    rand_cell= rand_cell + 1; if(rand_cell > rand_cell_max) rand_cell= 0; sleep 1; fork RandGen
}

Offline

#8 06/14/08 01:06

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

Re: The Random Number

func void RandGen(void) {
    rand_cell= rand_cell + 1; if(rand_cell > rand_cell_max) rand_cell= 0;
    rand_ammo= rand_ammo + 1; if(rand_ammo > rand_ammo_max) rand_ammo= 0;
    rand_invis= rand_invis + 1; if(rand_invis > rand_invis_max) rand_invis= 0;
    rand_shield= rand_shield + 1; if(rand_shield > rand_shield_max) rand_shield= 0;
    rand_dead= rand_dead + 1; if(rand_dead > rand_dead_max) rand_dead= 0;
    rand_weapon= rand_weapon + 1; if(rand_weapon > rand_weapon_max) rand_weapon= 0
    rand_flag= rand_flag + 1; if(rand_flag > rand_flag_max) rand_flag= 0;
    rand_music= rand_music + 1; if(rand_music > rand_music_max) rand_music= 0;
    sleep 1; fork RandGen();
}

the full function

And no matter what I try, I can't think of an all purpose random function that can be used multiple times in the same frame and get different answers.

Last edited by Gumby (06/14/08 01:06)


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

Board footer

Powered by FluxBB