View unanswered posts | View active topics It is currently Wed Nov 20, 2019 2:47 am






Reply to topic  [ 3 posts ] 
Calling Functions with both Motor Controls and Returns 
Author Message
Rookie

Joined: Sat Jul 11, 2015 3:53 pm
Posts: 6
Post Calling Functions with both Motor Controls and Returns
Hello there! First time poster. I am playing around with creating functions in ROBOTC and have a couple of questions I was hoping the community could help answer. I didn't want to overload this one post though since each question is a little different, so I'm going to break it up into a few posts

All of the examples I can find of ROBOTC functions online contain simple arithmetic and return the result of these calculations. Am I able to execute a function which both sends signals to the motor ports as well as does a calculation? For example:

Code:
bool moveforwards() {
   motor[port1] = 63;
   motor[port2] = -63;

   bool forwards_temp = true;
   return forwards_temp;


If I then call the function as follows, will I simultaneously turn the motors on AND return the boolean value?
Code:
forwards = moveforwards();


Or do I instead have to execute each of those parts of the function separately in order to (1) turn on the motors and (2) return the variable?
Code:
moveforwards();
forwards = moveforwards();


Thanks for the help!


Sat Jul 11, 2015 4:03 pm
Profile
Moderator
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Post Re: Calling Functions with both Motor Controls and Returns
So a function that is called executes all of its behavior. This means it will turn the motors on and return the value.

In other words the
Code:
forwards = moveforwards();
works as intended.

With the code you were showing it wouldn't be necessarily bad to call the function twice because you only turn the motors on but if your function went forward for 2 seconds and stopped the following code would make that action happen twice.
Code:
moveforwards();
forwards = moveforwards();


Sat Jul 11, 2015 10:30 pm
Profile
Rookie

Joined: Sat Jul 11, 2015 3:53 pm
Posts: 6
Post Re: Calling Functions with both Motor Controls and Returns
Thanks Tabor473, that is just what I needed to know!


Sun Jul 12, 2015 4:24 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.