other way of while loop?
I was trying to make something for my plugin that has this
PHP Code:
Does anyone knows of any other way to do this? |
Re: other way of while loop?
PHP Code:
|
Re: other way of while loop?
Quote:
and making it like that would give the 10th time to 0 |
Re: other way of while loop?
You can only store 10 numbers with an array[10] (0-9)
So by increasing the array to 11 you'll able to use 0 - 10, or 1-10 in your case. |
Re: other way of while loop?
Quote:
because i want the users to use the cmd so each person gets a number and they all have to be different numbers |
Re: other way of while loop?
Quote:
Because you initialize the array and don't assign numbers... In your case: x[0] = 0 x[1] = 0 x[2] = 0 x[3] = 0 ....and so on You should do something like that new x[] = {1,2,3,4,5,6,7,8,9,10} That should do the trick..for all numbers to be different you have to work out a function which stores the numbers given, and compare every new number with all the given ones... I'm a little tired maybe i'll post later a function when my coffee wake up my brain*lol* greetz regalis |
Re: other way of while loop?
Quote:
@ Crusher918 : use Cheap_Suit's hotfix :D. Also the is another thing you should consider: if random_num() returns 3 in a loop of 100 it will take a while to execute that command. Also random_num() seldom returns the max allowed value, so if that value is the only one left valid it will also take a while to do it. |
Re: other way of while loop?
Quote:
and for the random_num() -Sometimes the last number would return to 0 due to reaching the max value well is there any other way to do it so if its one left it will choose the last number? |
Re: other way of while loop?
There are 2 obvious ways you can do this:
1. extend the max value to 15 for instance. Thus you will have 5 possible values above the max allowed (15 might be a bit much but it will do the job). It will look like this: PHP Code:
PHP Code:
There are other methods you can use. For the purpose of this you could write a custom_random_num() function by yourself and handle those drawbacks in std random_num(); you could use Mel's RandomX module (also a bit too much :D), etc. |
Re: other way of while loop?
I think I know what you mean and I did something like this the other day with 2 for loops to have one give numbers and the other check the numbers for repeats.
Personally I'd like to see a function that could assign numbers to arrays for a random number set. I.e if you have an array[10] those array[0] through array[9] would each be given randomly one of the numbers between 1-10 so that none of the arrays have the same number like: new array[6] command(array) then with a get_command(array) you would know that: array[0] = 3 array[1] = 5 array[2] = 6 array[3] = 2 array[4] = 4 array[5] = 1 etc. etc. You could use this to easily shufle players to different groups or give each player unique things like every player has one random individual weapon or characteristic without having to check if a number has already been used. |
| All times are GMT -4. The time now is 10:31. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.