Geez, don't you just hate it (and feel remarkably stupid as well) when it's a logic error
It's now working fine and all I had to do was move one line out of a loop!
Old code:
FOR x = 1 TO 5
bAllIdle = 0
IF bIdle(x) = 1 THEN bAllIdle = 1
NEXT x
New code:
bAllIdle = 0
FOR x = 1 TO 5
IF bIdle(x) = 1 THEN bAllIdle = 1
NEXT x
For those that may be interested, here is the complete code:
REM Project: Dark Basic Pro Project
REM Created: Sunday, June 19, 2011
REM **************************** Main Source File ****************************
REM **************************************************************************
REM ******************************* INITIALISE *******************************
REM **************************************************************************
_GameStart:
`RANDOMIZE TIMER()
SYNC ON
SYNC RATE 120
SET DISPLAY MODE 800, 600, 32
PHY START
PHY SET TIMING 0.008333, 10, 0
REM **************************************************************************
REM ******************************* LOAD MEDIA *******************************
REM **************************************************************************
LOAD IMAGE "media/wood1.jpg", 1
LOAD IMAGE "media/pooltablecloth.jpg", 2
REM **************************************************************************
REM ****************************** SET UP ARENA ******************************
REM **************************************************************************
MAKE OBJECT PLAIN 1, 80, 160
ROTATE OBJECT 1, -90, 0, 0
TEXTURE OBJECT 1, 2
PHY MAKE RIGID BODY STATIC BOX 1
MAKE OBJECT box 2, 160, 75, 3
POSITION OBJECT 2, -40, 0, 0
ROTATE OBJECT 2, 0, 90, 0
TEXTURE OBJECT 2, 1
PHY MAKE RIGID BODY STATIC BOX 2
MAKE OBJECT BOX 11, 160, 200, 3
POSITION OBJECT 11, -40, 125, 0
ROTATE OBJECT 11, 0, 90, 0
HIDE OBJECT 11
PHY MAKE RIGID BODY STATIC BOX 11
MAKE OBJECT box 3, 160, 75, 3
POSITION OBJECT 3, 40, 0, 0
ROTATE OBJECT 3, 0, 90, 0
TEXTURE OBJECT 3, 1
PHY MAKE RIGID BODY STATIC BOX 3
MAKE OBJECT BOX 12, 160, 200, 3
POSITION OBJECT 12, 40, 125, 0
ROTATE OBJECT 12, 0, 90, 0
HIDE OBJECT 12
PHY MAKE RIGID BODY STATIC BOX 12
MAKE OBJECT box 4, 83, 75, 3
POSITION OBJECT 4, 0, 0, 80
TEXTURE OBJECT 4, 1
PHY MAKE RIGID BODY STATIC BOX 4
MAKE OBJECT BOX 13, 83, 200, 3
POSITION OBJECT 13, 0, 125, 80
HIDE OBJECT 13
PHY MAKE RIGID BODY STATIC BOX 13
MAKE OBJECT box 5, 83, 75, 3
POSITION OBJECT 5, 0, 0, -80
TEXTURE OBJECT 5, 1
PHY MAKE RIGID BODY STATIC BOX 5
MAKE OBJECT BOX 14, 83, 200, 3
POSITION OBJECT 14, 0, 125, -80
HIDE OBJECT 14
PHY MAKE RIGID BODY STATIC BOX 14
REM **************************************************************************
REM ****************************** SET UP DICE *******************************
REM **************************************************************************
FOR x = 6 to 10
LOAD OBJECT "media/die1.x", x
POSITION OBJECT x, RND(30) - 10, RND(40) + 35, RND(30) + 20
PHY MAKE RIGID BODY DYNAMIC BOX x
PHY ADD RIGID BODY FORCE x, 0, -20, -60, 2
PHY ADD RIGID BODY LOCAL TORQUE x, RND(360), RND(360), RND(360), 2
PHY SET RIGID BODY MASS x, 1000.0
PHY SET GRAVITY 0.0, 100.0, 0.0
NEXT
REM **************************************************************************
REM ************************ SET UP GLOBAL VARIABLES *************************
REM **************************************************************************
GLOBAL DIM nY(5)
GLOBAL DIM bIdle(5)
GLOBAL bAllIdle
GLOBAL bRoll
GLOBAL throw
bRoll = 1
bAllIdle = 0
FOR x = 1 TO 5
bIdle(x) = 0
NEXT x
REM **************************************************************************
REM ************************** SET UP OTHER OPTIONS **************************
REM **************************************************************************
SET AMBIENT LIGHT 30
PHY SET GRAVITY 0, -30, 0
POSITION CAMERA 0, 110, 75
POINT CAMERA 0, 0, -60
REM **************************************************************************
REM ******************************* MAIN LOOP ********************************
REM **************************************************************************
DO
CENTER TEXT SCREEN WIDTH() / 2, 2, "Press space to throw"
SET CURSOR 0, 20
FOR x = 1 TO 5
PRINT " "
PRINT bIdle(x)
NEXT
IF SPACEKEY() = 1 AND throw = 0 and bAllIdle = 0
throw = 1
FOR x = 6 to 10
PHY SET RIGID BODY ROTATION x, 0.0, 0.0, 0.0
PHY SET RIGID BODY POSITION x, RND(30) - 10, RND(40) + 35, RND(30) + 20
PHY ADD RIGID BODY FORCE x, 0, -20, -60, 2
PHY ADD RIGID BODY LOCAL TORQUE x, -180 + RND(360), -180 + RND(360), -180 + RND(360), 2
NEXT x
FOR x = 1 TO 5
bIdle(x) = 0
NEXT x
bRoll = 1
bAllIdle = 1
ELSE
PRINT " "
IF bAllIdle = 0
throw = 0
PRINT "ALL STOPPED"
ELSE
PRINT "STILL GOING"
ENDIF
ENDIF
PRINT " "
PRINT bRoll
IF bRoll = 1
PHY UPDATE
SYNC
rollDice()
FOR x = 1 TO 5
SET CURSOR 0, x * 10 + 390
PRINT "ROLLIN'"
NEXT x
ELSE
getDice()
FOR x = 1 TO 5
SET CURSOR 0, x * 10 + 390
PRINT nY(x)
NEXT
ENDIF
TEXT 0, 10, "FPS " + STR$(SCREEN FPS())
PHY UPDATE
SYNC
LOOP
END
REM **************************************************************************
REM ******************************* FUNCTIONS ********************************
REM **************************************************************************
REM ********************************* getDice ********************************
FUNCTION getDice()
sDiceID$ = ""
sHUDTag$ = ""
REM This is where we get the "pips" uppermost on the Dice. So, we need to loop through the Dice
REM and check which side is uppermost
FOR x = 6 TO 10
y = 1
IF OBJECT VISIBLE(x)
REM Get OBJECT POSITION
x1# = OBJECT POSITION X(x)
y1# = OBJECT POSITION Y(x)
z1# = OBJECT POSITION Z(x)
REM Get X Axis
MOVE OBJECT RIGHT x, 1
pxx# = OBJECT POSITION X(x)
pxy# = OBJECT POSITION Y(x)
pxz# = OBJECT POSITION Z(x)
MOVE OBJECT LEFT x, 1
REM Get Y Axis
MOVE OBJECT UP x, 1
pyx# = OBJECT POSITION X(x)
pyy# = OBJECT POSITION Y(x)
pyz# = OBJECT POSITION Z(x)
MOVE OBJECT DOWN x, 1
REM Get Z Axis
MOVE OBJECT x, 1
pzx# = OBJECT POSITION X(x)
pzy# = OBJECT POSITION Y(x)
pzz# = OBJECT POSITION Z(x)
MOVE OBJECT x, -1
pxx# = pxx# - x1#
pxy# = pxy# - y1#
pxz# = pxz# - z1#
pyx# = pyx# - x1#
pyy# = pyy# - y1#
pyz# = pyz# - z1#
pzx# = pzx# - x1#
pzy# = pzy# - y1#
pzz# = pzz# - z1#
REM normalise the Vectors
len# = pxx# * pxx# + pxy# * pxy# + pxz# * pxz#
len# = SQRT(len#)
pxx# = pxx# / len#
pxy# = pxy# / len#
pxz# = pxz# / len#
len# = pyx# * pyx# + pyy# * pyy# + pyz# * pyz#
len# = SQRT(len#)
pyx# = pyx# / len#
pyy# = pyy# / len#
pyz# = pyz# / len#
len# = pzx# * pzx# + pzy# * pzy# + pzz# * pzz#
len# = SQRT(len#)
pzx# = pzx# / len#
pzy# = pzy# / len#
pzz# = pzz# / len#
REM create the negative versions of the Vectors
nxx# = -pxx#
nxy# = -pxy#
nxz# = -pxz#
nyx# = -pyx#
nyy# = -pyy#
nyz# = -pyz#
nzx# = -pzx#
nzy# = -pzy#
nzz# = -pzz#
IF pxy# > pyy# AND pxy# > pzy# AND pxy# > nxy# AND pxy# > nyy# AND pxy# > nzy#
REM pxy is largest, so uppermost = 6
y = 6
ELSE
IF pyy# > pxy# AND pyy# > pzy# AND pyy# > nxy# AND pyy# > nyy# AND pyy# > nzy#
REM pyy is largest, so uppermost = 4
y = 4
ELSE
IF pzy# > pxy# AND pzy# > pyy# AND pzy# > nxy# AND pzy# > nyy# AND pzy# > nzy#
REM pzy is largest, so uppermost = 2
y = 2
ELSE
IF nxy# > pxy# AND nxy# > pyy# AND nxy# > pzy# AND nxy# > nyy# AND nxy# > nzy#
REM nxy is largest, so uppermost = 1
y = 1
ELSE
IF nyy# > pxy# AND nyy# > pyy# AND nyy# > pzy# AND nyy# > nxy# AND nyy# > nzy#
REM nyy is largest, so uppermost = 3
y = 3
ELSE
IF nzy# > pxy# AND nzy# > pyy# AND nzy# > pzy# AND nzy# > nxy# AND nzy# > nyy#
REM nzy is largest, so uppermost = 5
y = 5
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
nY(x - 5) = y
NEXT x
REMSTART Set relevant image in HUD
sHUDTag = "T2.btnDice" .. x
sDiceID = "Dice" .. y
IF ( x == 1 )
THEN
this.nPips1 ( y )
ELSEIF ( x == 2 )
THEN
this.nPips2 ( y )
ELSEIF ( x == 3 )
THEN
this.nPips3 ( y )
ELSEIF ( x == 4 )
THEN
this.nPips4 ( y )
ELSE
this.nPips5 ( y )
END
hComp = hud.getComponent ( hUser, sHUDTag )
IF ( string.compare ( sType, "A" ) == 0 )
THEN
IF ( hud.isComponentActive ( hComp ) )
THEN
hud.setComponentActive ( hComp, false )
END
ELSE
IF ( not hud.isComponentActive ( hComp ) )
THEN
hud.setComponentActive ( hComp, true )
END
END
hud.setComponentBackgroundImage ( hComp, sDiceID )
END
END
-- NB: WE ONLY NEED TO DO THIS AFTER ROLL #1
IF ( this.bFirst ( ) or this.bSecond ( ) )
THEN
-- Now, redisplay Roll Button with new Text
hComp = hud.getComponent ( hUser, "T2.btnRoll" )
x = this.nCurrentPlayer ( )
hud.setButtonText ( hComp, "Player " .. x .. " Re-roll when ready" )
IF ( string.compare ( sType, "A" ) == 0 )
THEN
IF ( hud.isComponentActive ( hComp ) )
THEN
hud.setComponentActive ( hComp, false )
END
ELSE
IF ( not hud.isComponentActive ( hComp ) )
THEN
hud.setComponentActive ( hComp, true )
END
END
IF ( not hud.isComponentVisible ( hComp ) )
THEN
hud.setComponentVisible ( hComp, true )
END
IF ( this.bFirst ( ) )
THEN
this.bFirst ( false )
this.bSecond ( true )
ELSE
this.bSecond ( false )
END
ELSE
this.bGetDice ( true )
this.bEndTurn ( true )
this.bCheckScore ( true )
END
for x = 1, 5
do
sTemp = "T2.btnDice" .. x
hComp = hud.getComponent ( hUser, sTemp )
IF ( string.compare ( sType, "H" ) == 0 )
THEN
IF ( not hud.isComponentActive ( hComp ) )
THEN
hud.setComponentActive ( hComp, true )
END
END
END
REMEND
ENDFUNCTION
REM ******************************** rollDice ********************************
FUNCTION rollDice()
bAllIdle = 1
FOR x = 1 TO 5
y = x + 5
nY# = OBJECT POSITION Y(y)
REM For the second roll, some Dice may no longer exist - these are moved to -1000 in Y
IF nY# > -1000
angX# = PHY GET RIGID BODY ANGULAR VELOCITY X(y)
angY# = PHY GET RIGID BODY ANGULAR VELOCITY Y(y)
angZ# = PHY GET RIGID BODY ANGULAR VELOCITY Z(y)
linX# = PHY GET RIGID BODY LINEAR VELOCITY X(y)
linY# = PHY GET RIGID BODY LINEAR VELOCITY Y(y)
linZ# = PHY GET RIGID BODY LINEAR VELOCITY Z(y)
angMX# = PHY GET RIGID BODY ANGULAR MOMENTUM X(y)
angMY# = PHY GET RIGID BODY ANGULAR MOMENTUM Y(y)
angMZ# = PHY GET RIGID BODY ANGULAR MOMENTUM Z(y)
linMX# = PHY GET RIGID BODY LINEAR MOMENTUM X(y)
linMX# = PHY GET RIGID BODY LINEAR MOMENTUM X(y)
linMX# = PHY GET RIGID BODY LINEAR MOMENTUM X(y)
pointVelX# = PHY GET RIGID BODY POINT VELOCITY X(y, nX#, nY#, nZ#)
pointVelY# = PHY GET RIGID BODY POINT VELOCITY Y(y, nX#, nY#, nZ#)
pointVelZ# = PHY GET RIGID BODY POINT VELOCITY Z(y, nX#, nY#, nZ#)
bIdle(x) = 1
IF angX# < 0.0005 AND angX# > -0.0005 AND angY# < 0.0005 AND angY# > -0.0005 AND angZ# < 0.0005 AND angZ# > -0.0005
IF linX# < 0.0005 AND linX# > -0.0005 AND linY# < 0.0005 AND linY# > -0.0005 AND linZ# < 0.0005 AND linZ# > -0.0005
IF angMX# < 0.0005 AND angMX# > -0.0005 AND angMY# < 0.0005 AND angMY# > -0.0005 AND angMZ# < 0.0005 AND angMZ# > -0.0005
IF linMX# < 0.0005 AND linMX# > -0.0005 AND linMY# < 0.0005 AND linMY# > -0.0005 AND linMZ# < 0.0005 AND linMZ# > -0.0005
IF pointVelX# < 0.0005 AND pointVelX# > -0.0005 AND pointVelY# < 0.0005 AND pointVelY# > -0.0005 AND pointVelZ# < 0.0005 AND pointVelZ# > -0.0005
bIdle(x) = 0
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ELSE
Rem These Dice are NOT being rolled, so are ALWAYS idle!
bIdle(x) = 0
ENDIF
NEXT x
bAllIdle = 0
FOR x = 1 TO 5
IF bIdle(x) = 1 THEN bAllIdle = 1
NEXT x
IF bAllIdle = 0 THEN bRoll = 0
ENDFUNCTION
Many thanks to HowDo for all the assitance.
Regards
Shando