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 / Looping

Author
Message
Mo$30
15
Years of Service
User Offline
Joined: 19th Sep 2009
Location:
Posted: 19th Sep 2009 21:29
Can someone please help me?!?!?! I need to loop this back around if the user types "1". Below is what I have, but I'm getting the error C2065: 'rerun' : undeclared identifier.



#include "DarkGDK.h"

void DarkGDK()
{
do
{
DWORD white = dbRGB (255,255,255);
DWORD black = dbRGB (0,0,0);
dbCLS (white);
dbInk (black, white);

dbPrint ("Enter red component [0-255]: ");
int red = atoi( dbInput() );

dbPrint ("Enter green component [0-255]: ");
int green = atoi( dbInput() );

dbPrint ("Enter blue component [0-255]: ");
int blue = atoi( dbInput() );

DWORD color = dbRGB (red, green, blue);
dbInk (color, white);
dbBox (270, 190, 370, 290);

dbInk (black, white);
dbPrint ("[1] Color [2] Quit: ");
int rerun = atoi( dbInput() );

}while (rerun == 1);

}
//end DarkGDK()
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 19th Sep 2009 23:01 Edited at: 19th Sep 2009 23:03
The issue here is that you declare rerun in the loop. try changeing the code as so.



Also, please remember that there is a code button

For more information on scope of variables in C++:
http://www.cplusplus.com/doc/tutorial/variables/

Scroll down to the section lables Scope Of Variables.

Have fun!

EYE R T3H +ick +ack +oe mester
Mo$30
15
Years of Service
User Offline
Joined: 19th Sep 2009
Location:
Posted: 19th Sep 2009 23:37
It isn't giving me the rejection anymore, but its not doing the loop either. Any ideas?
Paynterboi TicTacToe
16
Years of Service
User Offline
Joined: 23rd Dec 2007
Location: That one place
Posted: 22nd Sep 2009 01:31 Edited at: 22nd Sep 2009 02:32
First thing that I'm noticeing here is that you are not useing the while ( LoopGDK ( ) ) which COULD ( not 100% on this ) prevent your loop from affecting the window. Try moving your loop into a while ( LoopGDK ( ) ). Also if you do this than you need to add a break; statement after your do loop to break from the while ( LoopGDK ( ) ) or your loop will be initiated in definately.

Furthermore there is no dbSync() in your code either, dbSync() updates the display.

I recomend creating a new project for a 2d game and reading the comments in the source it gives you ( you can delete the project afterwords ). This will give you an explination of dbSyncOn(), dbSyncRate(), dbSync() and while ( LoopGDK ( ) ). In your case however, I wouldn't put a dbSync() at the end of the while ( LoopGDK ( ) ) only at the end of your do loop because if you put it in the GDK loop it will never update ( until you change the value of rerun from 1 but without visuals it may be difficult for you to tell that it is being changed )

Last time I gave you a copy of your source with corrections but I think you would benefit more from reading this and the comments in the 2d project I suggested you create.

P.S. I realized I told you about the code button but I find it is easier to type out the tags:
[c0de] /* blah blah */ [/c0de] use o instead of zero and it will display your code the same as my previous post.

P.P.S. I copied the code here and made it work, One thing that is needed is that even though I believe it is considered a bad habbit, in your case you need to add a dbSync() after every dbInput() call or the screen will not update to display the next message ( or the user's input ) Also, there is no protective measure against invalid inputs ( ie numbers within the 0-255 range or at the end when you ask for a 1 or 2. Other than that if the purpose of this program is to allow a user to input values to use a trial / error method to obtaining the rgb values of a desired color than this program is perfect ( assumeing the user inputs correct values and understands the reprocussions of not doing so )

I will put a copy of my completed source for you but PLEASE BE AWARE that you need to put for the effort to learn the gdk and c++, We will not write all your prgrams for you.

use the information contained in <darkGDK directory>/include ( .h files include all the commands that darkGDK has to offer ) as well as referense sites such as cplusplus.com



Now just another quick tip, This code is functional; however, I suggest trying to pick up good codeing habbits to make your code more understandable. Add Comments up the Wazoo, learn to use tabs, that sort of thing. One important note on this subject is not everyone is alike.

( The download contains a version that incpororates the protective measures I mentioned as well as one way you could control the flow of your program. The version actualy removes your do {} ( while rerun == 1 ) all together, check it out )

EYE R T3H +ick +ack +oe mester

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-20 15:29:46
Your offset time is: 2024-11-20 15:29:46