As I was studying some small algorithms to update Havoc Bug, I ran into a small issue and I could not find a solution for it. Once again, here I am asking some advice
I am doing a small code to randomly pick data from a data statement, in a way that the last picked data would stay out of the next "lottery". The random data here feeds the background color just for the sake of testing. It's the random_ok.bas file and it's working fine. It looks like this:
dim colorPointer = a dim timer = b colorPointer = (rand&7) MainLoop COLUBK = colorData[colorPointer] drawscreen timer = timer + 1 : if timer < 50 then goto MainLoop else timer = 0 CheckRepeatedColor temp1 = (rand&7) if temp1 = colorPointer then goto CheckRepeatedColor else colorPointer = temp1 goto MainLoop data colorData $30,$60,$D4,$1C,$92,$9A,$0E,$F6 end
When I add a new data to the statement and change...
(rand&7)
... into this:
(rand&8)
...since there's a new element in there, the code runs into a loop of two colors. That's in random_bug1.bas
I thought that maybe temp1 could be messing something, so I exchanged that for a variable. Looking like this:
CheckRepeatedColor randomNumber = (rand&8) if randomNumber = colorPointer then goto CheckRepeatedColor else colorPointer = temp1 goto MainLoop
With that, I ran into another strange situation. Now, the color changes once and then just stops, as if rand was just returning the same number always. That's in random_bug2.bas
I already fried my brain over this and I'm starting to wonder if this is one of those situations that the problem is right there in front of you but you've gone code blind. Ah, by the way, there's a typo on Random Terrain's chapter on rand. Here:
Any help will be greatly welcomed!















