rotate values in array
Blitz3D Forums/Blitz3D Programming/rotate values in array
| ||
Lets say that you anve an array like this and you want to rotate it...;dim the array dim fruit(9) for i = 0 to 9 whatever = rand(3) fruit (i)=whatever next i ; array is full now you can read the array by simply looking at address and assigning a variable to it: G=fruit(#) but how do you ratate values in the array? Like a slot machine? |
| ||
By hand. For example, move all the elements down by one and move the bottom one to the top. There's no automated way to handle this... |
| ||
Dim fruit(9) ;rotate temp = fruit(0) for iter = 0 to 8 fruit(iter) = fruit(iter + 1) next fruit(9) = temp |
| ||
Why not just use types? then you can Insert first after last whatever. |
| ||
Why rotate the values at all? Couldn't you have three variables, one for each reel, which identifies which slot on the reel is currently front-center. |
| ||
sybixsus, but then your mothod doesn't allow nudges etc |
| ||
Types would be good. I don't know enough about them to be able to read a specific type value though... as I read it you can use first,last, next, before... What if I wanted to read the seventh type value and determine what info it holds??? or if I wanted to compare the seventh type value and all its fields with the 19th type value and all its fields??? As it is I am going to have 9 rows or 9 shjowing and simply check for 3 across by comparing row positions for equal value. I see wolrons idea. I was thinking I had to set up a temp value and pass the values between. then as a ZERO comes up the setuprow function would fill in a new value. |
| ||
Another way is to store a offset value...something like:;some function calls ;each "rolls" the array, or at least gives the impression it does fruitroll(3) fruitroll(7) fruitroll(1) ;now the function FUNCTION fruitroll(offset%) FOR i = 0 TO 9 temp = ABS( ( i + offset ) MOD 10 ) value = fruit(temp) ;now you can print the value, display the graphic value..whatever NEXT END FUNCTION all you would need to do is keep track of a value indicateing the number of array spaces that have been rolled (note this number can be negative too...as long as it's an integer) say you have: ;just setting a value here rolls = 45829 ;the exact array value at that location value1 = fruit( ABS( rolls MOD 10 ) ) ;the array value two spaces below it, in terms of a slot machine value2 = fruit( ABS( ( rolls + 2 ) MOD 10 ) ) ;if you wish you can stick the math stuff into a function FUNCTION fruitindex(value%) RETURN ABS( value MOD 10 ) END FUNCTION ;then its just a matter of calling it value1 = fruit( fruitindex( rolls ) ) value3 = fruit( fruitindex( rolls - 37 ) ) ;etc.. for such a small array, actually moveing the data around isn't such a big deal...but when you get into larger arrays, and wish to "roll" them very often it can slow things down considerably. |
| ||
look it up in the forums. I asked this question earlier, and arrays CAN be rotated. |
| ||
Why rotate the values at all? Couldn't you have three variables, one for each reel, which identifies which slot on the reel is currently front-center. Yes, it can, if he uses floating point values. sybixsus, but then your method doesn't allow nudges etc |