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.

Dark GDK / Random number problem

Author
Message
Skolmen
15
Years of Service
User Offline
Joined: 28th Aug 2009
Location:
Posted: 6th Nov 2009 22:45
Hello!

I'm currently working on a game where I want a sprite to move with a random velocity between -3 and 3. Anyhow I don't know how to make a random number that can be lower than zero. The second problem is that when I do get a rondom number (between zero and three) the velocity keeps changing all the time, and the sprite is "lagging".

Would really apreciate some answeres

C++ newbie.
american eagle
17
Years of Service
User Offline
Joined: 2nd Aug 2007
Location:
Posted: 7th Nov 2009 01:49
first of all doing random number below 0 can be done simply like this:


your other problem you have to post snap of your code so i can tell what's the problem
cleonjones
15
Years of Service
User Offline
Joined: 24th Oct 2009
Location:
Posted: 7th Nov 2009 02:32
I'm guessing you're assigning the random velocity inside the LoopGDK() section of your code, you should set it outside and before that loop. If you want it set when something specific happens, I would use some if statements or a function of your own

?
Skolmen
15
Years of Service
User Offline
Joined: 28th Aug 2009
Location:
Posted: 7th Nov 2009 19:20
Well, assigning the velocity outside of the loop made the lagging go away. However, the dbRND(6)-3 seems to generate the same number every time, and the number generated is 3. Anyone know how to solve this?

C++ newbie.
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 7th Nov 2009 19:41
"int i;
i=dbRND(6)-3;
" will not go below zero



Are you using dbRandomize() every loop? if so, DON'T!


Your signature has been erased by a mod
american eagle
17
Years of Service
User Offline
Joined: 2nd Aug 2007
Location:
Posted: 7th Nov 2009 20:36
prasoc my friend u r wrong it should be dbRND(6)-3
the dbRND gives values from 0 to 6 and to make it go from -3 to 3 u shoud put -3 ur way will give numbers from -6 to - 3
though ur right about dbRandomize(dbTimer()) it should be just one time not in the loop
prasoc
16
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 7th Nov 2009 20:39
oh my bad. I don't even know what I was thinking of then lol


Your signature has been erased by a mod

Login to post a reply

Server time is: 2024-11-20 11:19:34
Your offset time is: 2024-11-20 11:19:34