srand(); C++ question

Pages: 12
Mar 7, 2013 at 5:20pm
Initially, just to confirm that that the array saveColour[][] and associated code is functioning correctly, you can omit the call to srand().

The only requirement for calling initColour(); is that it should take place before any calls to OGWindow::drawGrid(). Just put it somewhere near the start of the main function.

Once that is in place and working, put a call to srand(time(NULL)); just before the call to initColour()
Mar 7, 2013 at 5:30pm
ok making progress
Last edited on Mar 7, 2013 at 5:39pm
Mar 7, 2013 at 5:35pm
Did you add a function prototype void initColour(); at the top of the code?

Also are you using multiple .cpp files for this project?
Last edited on Mar 7, 2013 at 5:36pm
Mar 7, 2013 at 5:38pm
omg, ok, im an idiot. Fixed the problem, had to make it

void OGWindow::initColour()

not void initColour() which is what i was using >.<

..and it is back to changing colours on its own constantly every second :(

I'm beginning to think this can't be done >.<
Last edited on Mar 7, 2013 at 5:41pm
Mar 7, 2013 at 5:39pm
Aha - that sounds like good news.
Mar 7, 2013 at 5:45pm
yeh i'm using multiple files. Essentially, i'm doing coursework and the requirement is to create an AI program that automatically solves a maze (with varied results each run) and displays the results. That is where the marks lie.

The part I'm doing is completely unnecesary and gains me no extra credit, I know because i asked. I could just as easily have no random maze whatsoever and just one staple maze.

But i don't like easy, and because of all the time i put in, i want this and don't want to cop out..
Mar 7, 2013 at 5:48pm
Ok I see. Well, if it's nearly there, you may as well complete it. Even if you don't earn extra credit, somewhere down the line, the knowledge and experience gained will pay off.

..and it is back to changing colours on its own constantly every second :(

If you are actually using squareColour = saveColour[xValue][yValue];
then the implication would be that function initColour() is being called more than once.
Last edited on Mar 7, 2013 at 5:51pm
Mar 7, 2013 at 5:51pm
exactly, plus i think itll help for final testing because if the AI is still operating correctly despite different mazes, there's less likelihood of a random error sneaking up on me in marking.


If you are actually using squareColour = saveColour[xValue][yValue];
then the implication would be that function initColour() is being called more than once. 


that sounds like what is happening. So basically, I've redone what i had at the start in a more efficient way but not solved the problem xD?

and thanks again, i'm still learning heaps from this even if i'm encountering problems.
Last edited on Mar 7, 2013 at 5:57pm
Mar 7, 2013 at 5:55pm
I can only suggest again, make sure that initColour() is called just once at the start of the program. It sounds like you may have it caught up inside a loop somewhere.
Mar 7, 2013 at 6:01pm
you're a genius. It freakin works now xD xD xD

thank you for sticking with me all this time, you are awesome :D

(just had to move the calls to initColour and srand to a different method than initGrid)
Last edited on Mar 7, 2013 at 6:03pm
Mar 7, 2013 at 6:05pm
Glad it worked eventually. And no, not a genius, just a lot of practice.
Mar 7, 2013 at 6:09pm
..well you're my hero anyway :p
Topic archived. No new replies allowed.
Pages: 12