14M dice

rolsen

Member
why does my 14M dice roll always stop at 6

press:
if pin0=1 then faster

faster:
pause 50
let b6=30
goto chase

chase:
for b5=1 to 30
dec b6
pause b6
pins=%00000001
pause b6
pins=%00000010
pause b6
pins=%00000100
pause b6
pins=%00001000
pause b6
pins=%00010000
pause b6
pins=%00100000
pause b6
pins=%00000000
if b6=1 then dice
next b5
goto chase

dice:
pause 10
for b4=0 to 3
random w0
b2 = w0// 6 + 1
next b4
pause 10
let b3=b2
pause 10
if b3=1 then high 0
endif
if b3=2 then high 1
endif
if b3=3 then high 2
endif
if b3=4 then high 3
endif
if b3=5 then high 4
endif
if b3=6 then high 5
endif
wait 4
let pins=%00000000
end

I have looked at random in manual and hippys posts on random. glitch in my code I guess.
appreciate any suggestions.
 

rolsen

Member
Yes BCJ, needless to say I used the simulator to test & modify. Thought I had success. All inputs 10K tied to negative. Can't think what else to try.
 

boriz

Senior Member
Not sure, but you seem to be using IF in a strange way. Any statement that is not a goto/gosub should not appear on the same line with the IF. Try moving HIGH command to the line after the IF command, like this:
Code:
if b3=1 then
	high 0
endif
…
Etc.
Or maybe you could remove all the Ifs and use:
Code:
B3=b3-1
High b3
 

hippy

Ex-Staff (retired)
It probably comes down to seeding the random number in w0.

There's also a bug in the simulator. Try this ...

Do
w0 = 0
Random w0
Loop

Every time it executes the Random the result left in 'w0' is different. That shouldn't happen and won't happen on a physical PICAXE.

Moral : Always reduce a program to its bare minimum and check the foundations work first.
 
Top