Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Simple Dice Program Problem

Author
Message
Zarok
14
Years of Service
User Offline
Joined: 29th Nov 2009
Location: Gallowmere
Posted: 5th Jun 2010 02:26
Ok I apologize for the rather simple idea, but any how: I am following the book Hands on DarkBASIC professional, and I am currently on Activity 12.8, which gets you to type in the program given to create a simple dice calculation.

What it does it creates a single cell array, in a type holding dice1,dice2,dice3 records, then gives each record a random number from 1-6. If all three dices = 6 then the program displays all the dice rolls (Breaking every 31st). This is following code I wrote:



And I cant for the love of god get it to work! The problem is, it is just not stopping and displaying the results after the dice all get sixes. Now I have added an extra part to show the dice numbers each "Repeat". It is odd because even when I change it to show the rolls after one six on the first die, or two sixes on the first two dice, which I see on the screen come up, it does not show the results. Instead just continues to generate random dice rolls.

I am absolutely stumped, and despite it being a minor program that I could perhaps skip, I am worried if there might be a problem with my DarkBASIC Pro (Which is V7.4)

Help would greatly be appreciated! I hope it is just a stupid error but comparing with the solution this does not appear to be the case.

Zarok

http://darkbasicprogrammingworld.blogspot.com/

Byte < Kilobyte < Megabyte < Gigabyte < Terabyte < Petabyte < Exabyte < Zettabyte < Yottabyte(If only)
Digger412
17
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 5th Jun 2010 03:46
Well, one problem is the placement of this here: thrownumber = thrownumber + 1

You're storing the value in the variable throws(thrownumber).dice1, then add 1 to it, so you're checking throws(thrownumber+1).dice1. Also, when you define an array, it is static. When you try to ARRAY INSERT AT BOTTOM throws(0), you're trying to add a new element to a LIST, not an ARRAY (I think).

If you DON'T need to store your results, it would be much simpler.
Zarok
14
Years of Service
User Offline
Joined: 29th Nov 2009
Location: Gallowmere
Posted: 5th Jun 2010 04:10
List is just another name for a dynamically sized array, so it would not matter, furthermore I have just tested it to check it is storing the values at several later cells, so this does not appear to be the fault. But the code given (Despite my additions for debugging)is exactly what the book said to type. Now there is possibility that there is an error with it, but I doubt this.

http://darkbasicprogrammingworld.blogspot.com/

Byte < Kilobyte < Megabyte < Gigabyte < Terabyte < Petabyte < Exabyte < Zettabyte < Yottabyte(If only)
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 5th Jun 2010 18:39 Edited at: 5th Jun 2010 18:40
The book is wrong. The problem is that you are incrementing THROWNUMBER before you check it at the UNTIL part of your loop.

I would make incrementing THROWNUMBER conditional; i.e.(throws 1 - 3) NOT equaling 18. Like this:



Another way you could do it is to look at THROWNUMBER -1 for each of the dice when it is checked at UNTIL.



Hope this helps.
Zarok
14
Years of Service
User Offline
Joined: 29th Nov 2009
Location: Gallowmere
Posted: 5th Jun 2010 19:19
LBFN, thank you so much! The solution you offered does indeed work, and I am glad it was an error with the book. I am surprised I did not see it, and I am also surprised that those also following HODBP have not asked the same thing.

Anyhow it is all solved now thanks to your help

I will contact the author and alert him about the error also.

Zarok

http://darkbasicprogrammingworld.blogspot.com/

Byte < Kilobyte < Megabyte < Gigabyte < Terabyte < Petabyte < Exabyte < Zettabyte < Yottabyte(If only)
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 5th Jun 2010 19:29
You're welcome.

Sometimes, a second set of eyes is all you need. Good luck in your coding.

LB

Login to post a reply

Server time is: 2024-11-23 14:08:15
Your offset time is: 2024-11-23 14:08:15