View unanswered posts | View active topics It is currently Wed Sep 17, 2014 10:33 am






Reply to topic  [ 7 posts ] 
Help on Functions 
Author Message
Rookie

Joined: Fri Sep 10, 2010 12:19 pm
Posts: 7
Post Help on Functions
Hi everybody

I am trying to run a ROBOTC program with functions and I get an error

**Error**:Functions must be defined at main scope level

Do you have an example of its meaning?

Thanks very much for the help!

John


Thu Nov 29, 2012 11:44 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Help on Functions
It sounds like you have mismatched braces. Make sure your code is indented properly. This will help you to spot mismatched braces. I don't have RobotC in front of me but there is an automatic "format whole file" item in the Edit menu if I remember correctly.


Thu Nov 29, 2012 2:06 pm
Profile
Rookie

Joined: Fri Sep 10, 2010 12:19 pm
Posts: 7
Post Re: Help on Functions
Thanks MHTS

I will try your suggestions.

John


Thu Nov 29, 2012 3:08 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: Help on Functions
It often helps to use the "Format Whole File" button (under the Edit menu, in the Code Formatting section).


Thu Nov 29, 2012 3:14 pm
Profile
Rookie

Joined: Fri Sep 10, 2010 12:19 pm
Posts: 7
Post Re: Help on Functions
Hi, everybody

Thanks for your help, but I think I must be doing
something that I cannot detect.

I am attaching the code. I have some errors that are
not related to the function issues which I will correct
once this problem is resolved.

What I am trying to do is write one function to be used
for all robot movement, that is, go straight, turn, reverse, etc., by using "sub functions" within the main "move" function. I must be doing something that is totally wrong in declaring these "sub-functions".

Again, thanks for taking the time to look at this problem of mine.

John


Attachments:
test program.c [1.19 KiB]
Downloaded 203 times
Fri Nov 30, 2012 1:23 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Help on Functions
You're not calling functions correctly. Here is a simpler example of how to call functions:
Code:
void move(int time){
  motor[port1] = 127;
  wait1Msec(time);
}
main(){
  int moveTime = 500;
  move(moveTime);
}


Do not call functions by defining them, e.g. void move(int movetime);

p.s. Next time, please post your code in the [ code] [/code] tags provided.

_________________
sudo rm -rf /


Fri Nov 30, 2012 1:38 pm
Profile
Rookie

Joined: Fri Sep 10, 2010 12:19 pm
Posts: 7
Post Re: Help on Functions
Thanks magicode

PROBLEM SOLVED!!!!! I am a newbee!!!

John


Fri Nov 30, 2012 3:03 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.