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.

DarkBASIC Professional Discussion / Dice1 = RND(5)+1 doesn't work but Dice3 = RND(5)+1 does?

Author
Message
DrunkenAdvice
12
Years of Service
User Offline
Joined: 22nd Nov 2013
Location:
Posted: 22nd Nov 2013 01:54
So i'm just trying to learn DarkBASIC all on my lonesome.
Just started earlier today.
And I ran into this.
For a simple Dice rolling game,
Dice1 = RND(5)+1 has 100/100 times given me a 0.
Dice3 = RND(5)+1 however is giving me random numbers.

Now, for the sake of the code, it isn't an issue I guess.
This is more a question of WHY.
The only thing i changed was flipping all those Dice1's into Dice3's
And it started working.
Really odd...

Winning an argument against a troll, whom must admit that you are correct. The creature then kills itself in complete shame. Everything in world is a lil better.
That's how finishing a code feels.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd Nov 2013 05:49 Edited at: 22nd Nov 2013 05:52
Welcome to TGC DrunkenAdvice and the lovely forums of the DBP crowd!

Try adding:

Randomize timer()

To the top of your program. RND() uses a seed value and Randomize sets the seed for the random number generator. By setting it to the timer() it will be a different seed every time your program start (Though this have never been the case for me since I've always got random numbers that are different every time)

I've never heard of this issue before. How are your printing it to the screen to find out if the value is incorrect? Like maybe you've missed a letter or something that could through it off!

"Get in the Van!" - Van B
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 22nd Nov 2013 12:52
It's difficult to diagnose a problem without seeing the actual program. None the less the following seems to work as expected..



Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Nov 2013 12:55
The only thing I can think of that would cause that, is constantly setting the randomize seed to the same value. If not, well it has to be a problem somewhere else in your code.

I am the one who knocks...
DrunkenAdvice
12
Years of Service
User Offline
Joined: 22nd Nov 2013
Location:
Posted: 22nd Nov 2013 15:48
Well I would pull it up and show you, but for some reason every save I have made is blank.
So that's cool

Anyway, yes i did have the seen randomized
And the only thing i did to fix the code was change all instances of "Dice1" to "Dice3"
And it worked, I haven't revisited the issue since I'm far past.
I was just kinda wondering if there was something I was missing.

Since its not a known issue or trick or w/e
Im sure the issue was some lil syntax error that I accidentally fixed.


Anyway thanks for the quick responses!
Off to try and figure out why my saves can't be revisited...

Winning an argument against a troll, whom must admit that you are correct. The creature then kills itself in complete shame. Everything in world is a lil better.
That's how finishing a code feels.
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Nov 2013 15:51 Edited at: 22nd Nov 2013 15:52
They both work fine for me:



D.D.
DrunkenAdvice
12
Years of Service
User Offline
Joined: 22nd Nov 2013
Location:
Posted: 22nd Nov 2013 18:39 Edited at: 22nd Nov 2013 20:30
(Bloop)

Winning an argument against a troll, whom must admit that you are correct. The creature then kills itself in complete shame. Everything in world is a lil better.
That's how finishing a code feels.
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 22nd Nov 2013 18:50 Edited at: 22nd Nov 2013 18:52
Probably you reset it somewhere in the code to 0 before you print the result to screen, or you read wrong variable.You may have Dice1 = rnd(5)+1 and print Dice_1 for example.

Coding is My Kung Fu!
And My Kung Fu is better than Yours!
Duffer
23
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 24th Nov 2013 11:37
You might also have a use for this dice roll plugin I wrote...

http://forum.thegamecreators.com/?m=forum_view&t=208786&b=18

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Nov 2013 23:19 Edited at: 24th Nov 2013 23:21
Quote: "Dice1 = RND(5)+1 has 100/100 times given me a 0.
Dice3 = RND(5)+1 however is giving me random numbers.
...The only thing i changed was flipping all those Dice1's into Dice3's"

You must have misspelled Dice1 and corrected the mistake when you changed it to Dice3. I can be 90% sure of this because you say the value was always 0, and zero is the default value of an initialized variable, so you were more than likely printing the value of a new variable that hadn't been assigned any value.

This is an issue with Basic, you have to be very careful with your typing because if you spell a variable name wrong the compiler wont tell you, it will just create a new variable with the misspelled name.


Formerly OBese87.

Login to post a reply

Server time is: 2026-07-06 16:49:46
Your offset time is: 2026-07-06 16:49:46