Issues with an attempted finite state machine

Blitz3D Forums/Blitz3D Beginners Area/Issues with an attempted finite state machine

zortzblatz(Posted 2008) [#1]
switch=Rand(1,2)

While Not KeyHit(1)
Select switch

Case 1
ClsColor 255,0,0
Cls
switch = Rand(1,2)
Delay 200

Default
ClsColor 0,0,255
Cls
switch = Rand(1,2)
Delay 200

End Select 

Wend



When I run this code, it just selects one color and stays that color. What is preventing it from continuously reselecting colors and changing colors?


KillerX(Posted 2008) [#2]
I don't know. It's changing colours for me.


Ked(Posted 2008) [#3]
If you are using BlitzPlus, then you need to put a Flip() in there before Wend. I had to.


KillerX(Posted 2008) [#4]
It's not required for me. I tested with Blitz3D and Blitz Basic.


Mortiis(Posted 2008) [#5]
Working here, Blitz3D.


Andy(Posted 2008) [#6]
Worked like a charm, although i'm more into the psychedelic.

r=127
g=127
b=127

While Not KeyHit(1)
r1=Rand(0,2)-1
g1=Rand(0,2)-1
b1=Rand(0,2)-1

r=r+r1 
g=g+g1
b=b+b1

ClsColor r,g,b
Cls
Text 0,0,"Red:"+r+" Green:"+g+" Blue:"+b

Wend



tonyg(Posted 2008) [#7]
seedrnd?


Ross C(Posted 2008) [#8]
I think the seernd is a good suggestion. You could run that code 1000 times, in theory, and 1 could come up the first 100 times, or more. Different computers will produce different results. And the rnd seed is always the same upon starting an app in blitz. So your code will produce the EXACT same results everytime you run it, unless you seed the random number generator will a different start point.

You will generally always use millisecs() as your seed because of it's independantly changing value.


steve_ancell(Posted 2008) [#9]
Working OK in Blitz3D.


zortzblatz(Posted 2008) [#10]
Huh, I updated B3D and then tried running it again and it worked fine. Sorry for being a time waster.