Log in

View Full Version : Running Once?


amateurrobotguy
21-02-2005, 20:44
Where can I put my code so that it will execute itself completely only one time. So, if I turn the bot off and on, it will run again. There was a section in the UserRoutines.c FUNCTION NAME: User_Initialization that says it only runs once, but this doesn't seem like the right place for my code.

probizzle
21-02-2005, 22:52
Make a function somewhere in user_routines.c, put your code in there, and call that function from User_Initialization.

At least if you are trying what I think you are trying to do.

amateurrobotguy
22-02-2005, 12:31
What is stopping the program from going down the program and calling it, then it hits it again later and runs it? Is this programming language run-by-call-only and not run down the program. Right now I went into the users initialization and just pasted in my code snipet after where it says */Add you own...*/. Looks kind of messy, but only the robot will know :).

Ryan M.
22-02-2005, 13:58
What is stopping the program from going down the program and calling it, then it hits it again later and runs it? Is this programming language run-by-call-only and not run down the program. Right now I went into the users initialization and just pasted in my code snipet after where it says */Add you own...*/. Looks kind of messy, but only the robot will know :).Yes, it's "run by call" only. It will only run when it is called.

At least it's supposed to... ;)

amateurrobotguy
22-02-2005, 15:28
Once I call my function, does the function need to link back to the user initialization part just before it left off. I am assuming that it will automatically go back to right after where it was called upon completetion.

Ryan Cumings
23-02-2005, 01:30
Once I call my function, does the function need to link back to the user initialization part just before it left off. I am assuming that it will automatically go back to right after where it was called upon completetion.
Once you call the function, it will return to the point from where it was called once the function has returned
(If you didn't put in a return than the compiler will insert one for you at the end of the functions definition)

SpeakerSilenced
23-02-2005, 07:34
There is a simpler way of having something only run once...

int counter = 0;
if (counter == 0)
{
do whatever you want once;
counter++;
}
It will never be executed again unless you set counter = to 0... you can change the variable name too and name it whatever the function is supposed to do such as camera_settings, etc...

Joe Ross
23-02-2005, 15:33
There is a simpler way of having something only run once...

int counter = 0;
if (counter == 0)
{
do whatever you want once;
counter++;
}
It will never be executed again unless you set counter = to 0... you can change the variable name too and name it whatever the function is supposed to do such as camera_settings, etc...

That will be called every time unless counter is declared as a static int