Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Running Once? (http://www.chiefdelphi.com/forums/showthread.php?t=35176)

amateurrobotguy 21-02-2005 20:44

Running Once?
 
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

Re: Running Once?
 
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

Re: Running Once?
 
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

Re: Running Once?
 
Quote:

Originally Posted by amateurrobotguy
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

Re: Running Once?
 
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

Re: Running Once?
 
Quote:

Originally Posted by amateurrobotguy
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

Re: Running Once?
 
There is a simpler way of having something only run once...
Code:

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

Re: Running Once?
 
Quote:

Originally Posted by SpeakerSilenced
There is a simpler way of having something only run once...
Code:

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


All times are GMT -5. The time now is 10:00.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi