min rand and max rand function, with special selections...

You must understand the Game Editor concepts, before post here.

min rand and max rand function, with special selections...

Postby Sgt. Sparky » Wed Apr 18, 2007 8:24 pm

EDIT:
I feel sorta stupid posting this,
you can do this alot more easily by just putting texNumber or myvariable = -100 + rand(100); or whatever other number. xD
or my variable or textNumber = - 100 + round(rand(100));
here is a min rand and max rand thingie with special select functions...
Code: Select all
void mrand(int mn, int mx, char s[255], char t[255])
{
    float R;
    int S;
 
    R = mn;
    if(strcmp(t, "Round") == 0)S = 1;
    if(strcmp(t, "Norm") == 0)S = 2;
    if(S == 0)sprintf(s, "you may only select Round or Norm, not '%s'.", t);
    if(S == 1)
    {
        R = mn + round(rand(mx));
        sprintf(s, "%f", R);
    }
    if(S == 2)
    {
        R = mn + rand(mx);
        sprintf(s, "%f", R);
    }
}

the first number(left to right) is the minimum it can be.
the second number is the maxumum it can be.
right after that you select where you want it to be printed,
just like strcpy.
there is still one more thing after that... put Round for it to be a round number, and put Norm for it to be any number.
here is an example code that you put for the number to be from -1000 to 1000 and be printed into the actors text:
Code: Select all
mrand(-1000, 1000, text, "Norm");

all you do is put the bigger code into global and name it somthing than add it.
then you put the smaller code into the event that you want it to select the random number. :D
enjoy!
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest