I am writing a quite big macro thing, it's actually a simple game in
Calc, called ”Maxi-Yatzy” in Swedish, somewhat known as a Swedish
extended variant of Yahtzee, with 6 dice, 20 categories and you can
save two of your three rolls for later.

I ran into something that made me vary confused for quite some time.

I have a couple of dialogs, one of them is the game itself. Another
one is for selecting names from drop down boxes and things like that.
I did all this in Calc, so I can easily save all results ever played
in detail with date and time and everything, so the high scores list
will be huge eventually, which is one of the points with the whole
thing.

Anyway, in the games dialog, I have a check box called ”sort”. If the
player checked this box, the dice will be rolled as usual (I use some
UTF-8 characters, U+2680-U+2685 - ”⚀⚁⚂⚃⚄⚅” to display the results of
each roll), beu when the roll stops, a pause of one second will follow
and then all dice will be sorted. I figured that maybe not everyone
want their dice sorted, that's why I added that check box.

The strange thing was that if I selected ”Sort” then rolled the dice,
the dice showed up as sorted. If I then unchecked it again, they still
showed up as sorted, however wothout the one second pause…

So why was that?

I use two different arrays for the dice:
Dim Dice(1 To 6) As Integer ' All the six dice
Dim SDice(1 To 6) As Integer ' All the six dice sorted

So, if the checkbox is checked, the macro copies the sorted data to
the unsorted array, like this:
Dice()=SDice()

Very elegant, right?
Yes, I wish…
This very line was actually the reason for those strange things going on!

It seems like ”Dice()=SDice()” actually means that ”from now on Dice()
is just another name for SDice()”. It seems to work like pointers in
C/C++: Dice() points at SDice().

So what I did to correct this was to use a loop to copy all the values
one by one:
For i=1 To 6
        Dice(i)=SDice(i)
Next i

Well, going back to the macro now. I still have quite a lot problems to solve…

J.R.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to