forums

TNT Basic Forums > Programming Q&A
procedure definition names
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-02-2003 17:04

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Hi,
The following procedure looks OK to me, but TNT gives the error message, "A procedure cannot be declared inside another procedure" I have several more (longer ones) like this, although this is not true for all of them(?) anyone got any ideas on how I could get around this or what might be causing it? There are no errors where it is called, thanks in advance to anyone who can help.

Procedure EndGame()
set pen colour black
paint canvas
load images 129
set pen colour white
draw text 104,66," Your time is up - Goodbye!"
wait mouse click
unload images 129
TitleScreen()
End proc

thanks,
Mark_667

01-02-2003 17:54

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

There's probably a procedure declared before this one which is missing its 'End Proc' statement.

Thanks,

Mark

01-10-2003 10:54

Posted by:
mark_667

Location:
England

Click Here to Email mark_667   Find more posts by mark_667

Oops!

Hi,
Having done as suggested, I found the number of compiler errors in TNT had jumped from 16 to 120! Having included the new code edits, I tried to undo the new end proc statements inserted (hoping to put the no. of errors back to 16), this brought it down to 48 - not the same number as before (?)

It turns out that the End Proc statements highlighted as being syntax errors all have something wrong within the procedures, even when I put the End proc statements back in, but none of these were highlighted before (?) Some that don't still return the original error,'A procedure cannnot be declared inside another procedure' even though it has been declared OK.
Have I deleted something else accidentally that could be causing all these extra errors?
In this case the first line is highlighted, both 'x' and 'speed' even though x is obviously the x co-ordinate and speed has been consistantly declared in all neccessary procedures. This is the same for commands using the y=y+speed functions to move the sprites around the screen, regardless of their current position.

Sprite 7
x=x+speed 'moves the sprite to face the right of the screen

Thanks again in advance,
mark_667

01-12-2003 01:03

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Compiler Errors

The problem with compiler errors is that it's often very difficult for TNT Basic to actually figure out what the problem is and report it in a sensible way.

Simple examples:

if you put an 'if' statement without an 'end if' statement, is the problem that you've missed an 'end if' off, or inserted an extra 'if'?

if you use a variable that you haven't declared, does that mean that you mistyped the varible name (perhaps you meant another variable?) or that you simply forgot to declare the variable?

Basically, what I'm trying to say is you must always take the compile errors from any programming language with a pinch of salt.
If TNT Basic says there is a compile error, then there is one, and it is probably somewhere near where it says it is, but it could well be that your error has confused TNT into thinking that the error is something that it isn't, because your error has made TNT think your code is trying to do something other than what you think it's trying to do (!).

Here's a guide to trying to deal with large numbers of errors:

Start with the first error, ignore the rest. They are quite possibly side effects of the first error and could well change/go away when you fix that one. This is the golden rule.

Look at the code highlighted, if it's a variable then check that the variable is declared. If it is declared outside of a procedure, but the error is inside a procedure, then check that varible is declared as 'global'.

If the error is a syntax error then check that you have all end ifs, wends, untils/forever and end procs in place. If you are missing them that can cause these sort of errors. A sensible way to manage this is to use indenting of code.
Simply tab your code in by one tab when you make an if/while/do/procedure and tab it out again when you finish.

Eg: (apologies for poor web formatting here white space has been replaced with -, in your code, this would be a space)

if a=b
----------->' This code is idented because it is inside the 'if'
----------->while a>0
----------------------->' this is indented twice because it's inside the while
----------------------->' and the if.
----------->wend
end if

Indenting your code like this helps you keep track of what constructs (like if/while/do/procedure etc) you are in. If you finish some code but are still tabbed in, then you know you must have missed somthing out!

Finally, if all else fails, use TNT Basic's 'Rem selection' command to rem out all your code, then unrem it one line at a time until the error begins occurring again, then you can see what you did and figure out what it's an error.

If all else fails just post your code here, it will always help others who are going through similar torment! Remember, as with your example, the code highlighted isn't always the code at fault, it could be an error earlier in the program.

Any one else got any helpful tips?

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.