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 / Getting a random number

Author
Message
Neon Sheild
13
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 28th Aug 2010 07:57
Hi guys,
Sorry if this is a newbie question (which it probably is, since I'm new to both C++ and the GDK!), but I'm making my own version of a pokemon game.
I wanted to make it so each time you clicked "run" in battle, and random number would be retrieved, and then depending on the number, you would either succeed or not.
However, I was looking at a few other threads and following their advice, and the only thing they suggested, according to them, would make it so each time the program is run it would determine a new random number.
So I'm asking how would you make it so each time you click "run" a different number is rolled each time, not some pre-deteremined number that it makes it so you succeed every time or fail every time during that play session.

I'm currently putting this in with my declarations and stuff "dbRandomize(dbTimer);", and then later setting a variable equal to "dbRND".
What should I do?




P.S. Sorry for the lengthy post...

ß ñéøπ $H£ÏLd îS †Hë Måñ ß

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 28th Aug 2010 18:21
dbRND(int Top) is essentially ((rand() % Top) + 1), and dbRandomize is equivalent to srand, in case you want to use the GDK functions.



“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Neon Sheild
13
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 28th Aug 2010 21:34
interesting...I think I see what you're saying
But one quick question though...I would only either use the the code from before "or here's a function" or the code after that right? Like, I wouldn't need both?

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
Bran flakes91093
15
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 28th Aug 2010 22:15
Nah those were just separate examples. I just threw it in a function to make it easy.

Sorry I made it kind of confusing by throwing it all in one code snippet .

The second example (after the function) was just to show how you could factor in other components, like health into probability.

“C++ : Where friends have access to your private members.”
-Gavin Russell Baker
Neon Sheild
13
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 28th Aug 2010 22:26 Edited at: 28th Aug 2010 22:55
ah, ok I see.
lol no problem about the confusion, I get it now lol
Thanks!

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
Neon Sheild
13
Years of Service
User Offline
Joined: 27th Aug 2010
Location: Mt. Olympus
Posted: 29th Aug 2010 07:50
I'm sorry, I have one more question though...
what is "srand" and "rand"? They work, but I just don't know what they actually are...

Perhaps, I theoretically might possibly have potential to hypothetically maybe have the chance to attempt something.
Dragon_Soldier
14
Years of Service
User Offline
Joined: 2nd Dec 2009
Location:
Posted: 29th Aug 2010 17:58
srand and rand are C++'s way to generate random numbers. They are similar to dbRND and dbRandomize. srand generates the seed of the random numbers (the starting one) and rand generates a random number. Hope this helped.

Login to post a reply

Server time is: 2024-07-02 09:23:59
Your offset time is: 2024-07-02 09:23:59