Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.
Moderator: Coders of Rage
RandomDever
Chaos Rift Regular
Posts: 198 Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++
Post
by RandomDever » Sun Apr 05, 2009 10:29 pm
Make a C++ Debug Prompt?
Is it possible?
Falco Girgis
Elysian Shadows Team
Posts: 10294 Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:
Post
by Falco Girgis » Mon Apr 06, 2009 12:25 am
No. Not without having a C++ compiler/interpreter going in real-time.
It would be infinitely more easy to make an in-game assembly debug prompt. It would be an extremely platform specific endeavor, but it's very possible to do it on anything (Dreamcast even).
RandomDever
Chaos Rift Regular
Posts: 198 Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++
Post
by RandomDever » Mon Apr 06, 2009 12:55 am
Thanks for the reply.
BTW What about a random number generator function that would take the minimum and maximum number it could genereate?
Falco Girgis
Elysian Shadows Team
Posts: 10294 Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:
Post
by Falco Girgis » Mon Apr 06, 2009 7:09 am
rand() and being a little bit of a smartass will work.
Where number is equal to min+number of random numbers = max random number.
So if you want 10-20 randomly:
avansc
Respected Programmer
Posts: 1708 Joined: Sun Nov 02, 2008 6:29 pm
Post
by avansc » Mon Apr 06, 2009 9:24 am
Code: Select all
int random_range(int min, int max)
{
return rand()%(max-min)+min;
}
personally i would make it like this.
Code: Select all
double random(double min, double max)
{
return (rand()/((double)(RAND_MAX)+1.0))*(max-min)+min;
}
that way you get a double back. its not better. its just nice when you need a random number with a bit more "meaning"
you can just use an int case on the call if you just need an int value.
(int)random(lower, upper);
anyways.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Falco Girgis
Elysian Shadows Team
Posts: 10294 Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:
Post
by Falco Girgis » Mon Apr 06, 2009 12:32 pm
Thanks, avansc. I had a hard time putting what I meant into words. Your first function is exactly what I was trying to say.
RandomDever
Chaos Rift Regular
Posts: 198 Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++
Post
by RandomDever » Mon Apr 06, 2009 1:26 pm
Thanks guys the random_range function works perfectly.
Sweet!
Edit: Now back to work