How do I?

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

Post Reply
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

How do I?

Post by RandomDever »

Make a C++ Debug Prompt?
Is it possible?
:shock:
User avatar
Falco Girgis
Elysian Shadows Team
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:

Re: How do I?

Post by Falco Girgis »

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
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: How do I?

Post by RandomDever »

Thanks for the reply. :mrgreen:
BTW What about a random number generator function that would take the minimum and maximum number it could genereate?
User avatar
Falco Girgis
Elysian Shadows Team
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:

Re: How do I?

Post by Falco Girgis »

rand() and being a little bit of a smartass will work.

Code: Select all

rand()%number+min
Where number is equal to min+number of random numbers = max random number.

So if you want 10-20 randomly:

Code: Select all

rand()%10+10
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

Re: How do I?

Post by avansc »

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"
User avatar
Falco Girgis
Elysian Shadows Team
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:

Re: How do I?

Post by Falco Girgis »

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
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: How do I?

Post by RandomDever »

Thanks guys the random_range function works perfectly.
Sweet! :mrgreen:
Edit: Now back to work Image
Post Reply