Ok finally got around working on my level again. But I need to improve my cog because it has some flaws which can detoriate gameplay.
There are 12 random integers being generated using Rand() and truncating.
It is now however imperative that all the generated numbers are NOT equal to one another. So what I need is somekind of check to see if a newly created number isn't already in use.
Part of my code. numdoors is currently set to 12, so 12 random numbers are generated in this for loop. For each generated number a door is either closed or openend, depending on its current state. In the once in a ~10,000 chance of 30 being returned with generating random numbers ALL doors are changed position.
The problem is a door might be called multiple times and have to open and then immediately close again, which I want to avoid.
curently rndt (the truncated randomvalue) is overwritten each loopcycle, so I figure I'll have to be using rndt[rndint] and assign 11 more rndt-symbols.
But I'm confused as to what code I can use to check if the current rndt isn't already used or not and if so generate a new one and check again, just as long until it's unique.
Any help would be appreciated.
There are 12 random integers being generated using Rand() and truncating.
It is now however imperative that all the generated numbers are NOT equal to one another. So what I need is somekind of check to see if a newly created number isn't already in use.
Code:
for ( rndint = 0; rndint < numdoors; rndint = rndint + 1 ){ //repeat 0-11 rnd = Rand() * 30; //random number between 0 and 30 rndt = rnd - ( rnd % 1 ); //truncate random value using modulo //Here must come some code to test if it isn't used already PlaySoundGlobal(open, 1, 0, 0x100); if ( rndt == 30 ) { //in the special situation of rand() giving 1 rndint = numdoors; for ( dint = 0; dint < 30; dint = dint + 1 ){ // for 0-29 if ( GetCurFrame( door[dint] ) == 1 ){ //if open MoveToFrame( door[dint], 0, dspeed ); //close } //end if open else if ( GetCurFrame( door[dint] ) == 0 ){ //if closed MoveToFrame( door[dint], 1, dspeed ); //open } //end if closed } //end for 0-29 } //end if special situation else if ( GetCurFrame( door[rndt] ) == 1 ){ //if open MoveToFrame( door[rndt], 0, dspeed ); //close } //end if open else if ( GetCurFrame( door[rndt] ) == 0 ){ //if closed MoveToFrame( door[rndt], 1, dspeed ); //open } //end if closed } //end for 0-11
Part of my code. numdoors is currently set to 12, so 12 random numbers are generated in this for loop. For each generated number a door is either closed or openend, depending on its current state. In the once in a ~10,000 chance of 30 being returned with generating random numbers ALL doors are changed position.
The problem is a door might be called multiple times and have to open and then immediately close again, which I want to avoid.
curently rndt (the truncated randomvalue) is overwritten each loopcycle, so I figure I'll have to be using rndt[rndint] and assign 11 more rndt-symbols.
But I'm confused as to what code I can use to check if the current rndt isn't already used or not and if so generate a new one and check again, just as long until it's unique.
Any help would be appreciated.