Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / error - "you have hit a function declaration mid-program"?

Author
Message
Cigaboo
18
Years of Service
User Offline
Joined: 12th May 2006
Location:
Posted: 30th May 2006 03:35
I was trying out functions for the first time today, trying to
make a function to automate object and image numbering and also
a function to calculate the distance between two objects.
However, whenever I compile + try to run, I get:
"Early exit error. You have hit a function declaration mid-program."

What does this error mean? I see nothing wrong with my functions (in terms of producing an error). The error occurs at the first function declaration.

Cryptoman
21
Years of Service
User Offline
Joined: 24th Nov 2003
Location: Utah Mountains
Posted: 30th May 2006 07:39
You have no END between your main program and the start of your functions. Something Lee has done to the compiler, this seems to be required now.


Cigaboo
18
Years of Service
User Offline
Joined: 12th May 2006
Location:
Posted: 30th May 2006 08:13
Hi, thanks for the response. Why would an END be placed between
the main program and the start of functions? Do you mean that functions have to be declared at the "bottom" of your program code? I'm rather surprised this isn't clearly stated anywhere that I've checked.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 30th May 2006 11:07 Edited at: 30th May 2006 11:08
because when you press escape key during your loop, it exits the loop and keeps reading down all your source code.
you would want to end your program before you reach functions or gosubs or anything else. and generally people write functions and gosubs below the main loop.

Too Sexy
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 30th May 2006 17:31
dbp programs attempt to run from first line to last, since functions are meant to be called from the main code, then returned back to the main code, the overall app code needs an end at the end of the main code but before the group of functions and subs start.

Main Code
.
.
.
.
End

Functions & Subs

Cigaboo
18
Years of Service
User Offline
Joined: 12th May 2006
Location:
Posted: 30th May 2006 20:32
Thanks for the responses, guys. I get it now. Hopefully this thread will help any other newb who encounters the same question.
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 1st Jun 2006 18:24
I would reccomend putting all functions in seperate file(s) (includes) and just use the main source file your loop and main logic etc.

My W.I.P project

Login to post a reply

Server time is: 2024-11-27 18:30:21
Your offset time is: 2024-11-27 18:30:21