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.

DarkBASIC Professional Discussion / Function Declaration Error

Author
Message
Troysmadhouse
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 11th Mar 2014 16:17
OK... I received a new error today, but I can't figure out what it means. "Function Declaration 'wkout' must be outside any program nests at line 389"

I created a simple function and called it wkout

Function wkout (k)
do
if Scancode ( ) = k
do
if scancode( ) <>K then exit
loop
exit
endif
loop
endfunction

Now, this works really well, but all of a sudden it doesn't like the position of the code. Any idea where it should be, if not within the main loop?

Thanks!

Troysmadhouse
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Mar 2014 21:01
The problem is with the previous code. You have forgotten to close an if/endif, do/while or similar.

ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 11th Mar 2014 22:48
Quote: "Any idea where it should be, if not within the main loop?"


Function declaractions should be at the bottom of your code, hence below the main loop.

Rick the Programmer
22
Years of Service
User Offline
Joined: 23rd Mar 2004
Location: Maryland
Posted: 11th Mar 2014 23:46 Edited at: 11th Mar 2014 23:52
The Function declaration is fine, the code should work well


The error means that the function is declared is within a nest. A nest being some command that is closed by another. If/Endif, While/Endwhile, Repeat/Until, Do/Loop, For/Next, Select/Endselect, Case/Endcase, subroutines, and even Function/Endfunction are all examples of nests. You must do the Function/Endfunction nest outside of any other nest, out in the open code, so to speak.

For example, this use of your function design works.



While this one produces the error you're getting.


Ensure that the function declaration is outside of all other nests. This is just an explanation behind what the others were saying earlier.

P.S. WOW the number variable racks up quickly considering it increments by 1 at a time per cycle of the loop while K is pressed. LOTS of loops in the split second you hold it down to tap the key. The smallest number of loops I could get from one press was 70,000.

Ask not for whom the bell tolls;
It tolls for ye!
Troysmadhouse
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 12th Mar 2014 17:53
Perfect... I will give that a try today when I get home. Thank you so much for all your help!!!

Troysmadhouse

Login to post a reply

Server time is: 2026-07-06 19:40:00
Your offset time is: 2026-07-06 19:40:00