I was editing some code I have, actually a game with dice and stuff,
but that doesn't matter, I suppose.
So I ran into a problem, and I copied the troubling part of the code
to a separate document for test driving.
However, the test code runs perfectly, but not within the game of mine!
I ran the game on another computer but another version of
OpenOffice.org (actually the first computer runs LibreOffice 3.3.3),
but the results were exactly the same.
Here's the test code. I have a message box after almost every
statement so I can see what happens. I added some extra comments in
the code.
REM ***** BASIC *****
Option Explicit
Option Compatible
Type DieStatistics
Value As Integer
Count As Integer
End Type
' The variable DiceFreq, declared below this comment, tells us which
two die values that are most frequent. For example, if the six dice
are 133455,
' DiceFreq will contain:
' DiceFreq(0).Value: 5 (the most common value is 5)
' DiceFreq(0).Count: 2 (2 dice have the value 5)
' DiceFreq(1).Value: 3 (the second most common value is 3 – in this
case there are two of both 3 and five, but higher value has priority)
' DiceFreq(1).Count: 2 (2 dice have the value 3)
' This makes it very easy for us to calculate things later,
calculations that are not present in this short example though.
Private DiceFreq(1) As DieStatistics '
Sub Test0
' NDice tells us how many there are of each die value. In the above
example, NDice(4)=1, since there are 1 die with the value 4.
Dim NDice(1 To 6) As Integer, i As Integer
' Here we set the values of NDice for an example where this is known
to fail, that is what NDice would contain if the dice were 112345
' NDice(1)=2, NDice(2)=1 and so on.
For i=2 To 5
NDice(i)=1
Next i
NDice(1)=2
' Here's where I calculate the values for DiceFreq by going through
NDice from 6 to 1.
For i=6 To 1 Step -1
If NDice(i)>DiceFreq(0).Count Then
DiceFreq(1).Count=DiceFreq(0).Count
DiceFreq(1).Value=DiceFreq(0).Value
MsgBox DiceFreq(0).Value & ": " &
DiceFreq(0).Count & " st." & Chr(13) & _
DiceFreq(1).Value & ": " & DiceFreq(1).Count &
" st."
DiceFreq(0).Count=NDice(i)
DiceFreq(0).Value=i
MsgBox DiceFreq(0).Value & ": " &
DiceFreq(0).Count & " st." & Chr(13) & _
DiceFreq(1).Value & ": " & DiceFreq(1).Count &
" st."
ElseIf NDice(i)>DiceFreq(1).Count Then
DiceFreq(1).Count=NDice(i)
DiceFreq(1).Value=i
MsgBox DiceFreq(0).Value & ": " &
DiceFreq(0).Count & " st." & Chr(13) & _
DiceFreq(1).Value & ": " & DiceFreq(1).Count &
" st."
EndIf
Next i
MsgBox "Final reults:" & String(2,Chr(13)) & DiceFreq(0).Value & ": "
& DiceFreq(0).Count & _
" st." & Chr(13) & DiceFreq(1).Value & ": " & DiceFreq(1).Count & "
st."
End Sub
Now, while this works perfectly as a stand-alone subroutine, it
doesn't work in the game. What happens in the game is that everytime I
change the value of DiceFreq(i).Value or DiceFreq(i).Count, BOTH
instances are changed, for example if I set DiceFreq(0).Value to 5,
DiceFreq(1).Value is also set to 5 and I just can't figure out why!
In the game the corresponding subroutine is called from another
module, but I simulated that too in my test, but still it ONLY fails
in the game.
I can upload my game document (the debug version) somewhere if needed.
What on earth could possibly cause this? I'm just out of ideas!
Help…?
Kind regards
Johnny Rosenberg
ジョニー・ローゼンバーグ
--
-----------------------------------------------------------------
To unsubscribe send email to [email protected]
For additional commands send email to [email protected]
with Subject: help