AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how to select random variable? (https://forums.alliedmods.net/showthread.php?t=193963)

kiki33hun 08-24-2012 06:48

how to select random variable?
 
how to select random variable?

Like:
new variable1;
new variable2;
new variable3;


I should pick one of these up to my dating!
Like:

random_function(variable1,variable2,variable3 ), and return variable on random! Example return: variable3

Thanx, sorry my english xD

jimaway 08-24-2012 07:00

Re: how to select random variable?
 
random_function(variable1, variable2, variable3) {
switch (random_num(0,2)) {
case 0: return variable1
case 1: return variable2
case 2: return variable3
}
}

or just have those variables as an array

new variable[3]
variable[random_num(0,2)] //random value from array

kiki33hun 08-24-2012 07:07

Re: how to select random variable?
 
Lol, thanx

Napoleon_be 08-24-2012 10:59

Re: how to select random variable?
 
Can you use like enum?

for example:
PHP Code:

enum _:Variables {
    
Variable1,
    
Variable2,
    
Variable3,
    
Variable4


and then just use
PHP Code:

switch(random(3)) {
    case 
0Variable1
    
case 1Variable2
    
case 2Variable3
    
case 3Variable4


Isn't this possible aswell?

Exolent[jNr] 08-24-2012 14:56

Re: how to select random variable?
 
It would be better to use an array, because it is shorter code and easier to extend.

Code:
new variable1; new variable2; new variable3; random_variable() {     switch(random(3))     {         case 1: return variable2;         case 2: return variable3;     }     return variable1; }
Code:
new variables[3]; random_variable() {     return variables[random(sizeof(variables))]; }

fysiks 08-24-2012 19:03

Re: how to select random variable?
 
Quote:

Originally Posted by Napoleon_be (Post 1781392)
Can you use like enum?

for example:
PHP Code:

enum _:Variables {
    
Variable1,
    
Variable2,
    
Variable3,
    
Variable4


and then just use
PHP Code:

switch(random(3)) {
    case 
0Variable1
    
case 1Variable2
    
case 2Variable3
    
case 3Variable4


Isn't this possible aswell?

No. You don't do anything in your code.

Napoleon_be 08-24-2012 20:17

Re: how to select random variable?
 
Quote:

Originally Posted by fysiks (Post 1781834)
No. You don't do anything in your code.

It's not a full code, just trying if this would work or not.

Backstabnoob 08-24-2012 20:59

Re: how to select random variable?
 
No it won't unless the values are constants.


All times are GMT -4. The time now is 05:48.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.