View unanswered posts | View active topics It is currently Sun Sep 21, 2014 6:13 pm






Reply to topic  [ 3 posts ] 
Methods in Robot C 
Author Message
Rookie

Joined: Tue Oct 25, 2011 4:18 pm
Posts: 2
Post Methods in Robot C
Have simple question, is it possible to code indiviutal methods in robot C. Asking this becasue the task main method is getting to much code in it that its hard to keep track off... so just wondering if possible to make a method away from the task main... and beable to call the method (method's name that you create outside the main method) in the task main method.

-Dan :)


Tue Oct 25, 2011 4:22 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Methods in Robot C
They're called functions and it's quite easy to do. Consider the following:
Code:
// This is a function
int addTwoNumbers(int one, int two)
{
  int result = one + two;
  return result;
}

// This is the main task
task main ()
{
  int aNumber = 0;
  aNumber = addTwoNumbers(4, 5);
  nxtDisplayTextLine(0, "Result: %d", aNumber);
  wait1Msec(5000);
}


- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Oct 25, 2011 4:29 pm
Profile WWW
Rookie

Joined: Tue Oct 25, 2011 4:18 pm
Posts: 2
Post Re: Methods in Robot C
Thank you!


Tue Oct 25, 2011 4:30 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.