#Keyscript error msg
4 messages in this thread
Hello Martin & KUB-
I am using The Script Extension 1.0 to process some ASCII format files in 3DS
R4. I am really stumped on a bug in a KXP script. The error message I get is
"Too Many FOR/ NEXT Loops" but I really don't have that many (only 6 in the
whole script, and the maximum nesting is 3 deep). I suspect that there is some
other cause for this error, but I can't seem to isolate it. I –AM– using
GOTO statements to jump out of some loops. There is one place where I re-start
an outer loop many times, but this seems like the same thing as an inner loop
that gets re-started on every pass, so I doubt that it should cause any strange
behavior.
I'm stumped. Are there any known bugs that cause this error message to show
up? Any hints on how to get around it? Also, is there a newer release of
T.S.E. than 1.0?
Thanks for any help,
Mike Wall
Mike,
>> I –AM– using GOTO statements to jump out of some loops. <<
I'd guess that's your problem. I think there's a correct way to jump out of a
loop before you need to and there may be a command to do so but my manuals are
at work. In the absence of this, one way of getting out of the for/next cleanly
would be to set the a for variable at it's exit value. Here's a pseudo
code-like example:
for i = 1 to 10
do something
'check to see if we need an early exit to this loop
if condition exists then i=10
if i=10 then goto skip
do something
@skip
next i
there's probably a cleaner way of doing this but not at 20:42 on Labour Day
<g>.
>> The error message I get is "Too Many FOR/ NEXT Loops" but I really don't
have that many (only 6 in the whole script, and the maximum nesting is 3
deep). I suspect that there is some other cause for this error, but I can't
seem to isolate it. I –AM– using GOTO statements to jump out of some loops.
There is one place where I re-start an outer loop many times, but this seems
like the same thing as an inner loop that gets re-started on every pass, so I
doubt that it should cause any strange behavior. <<
Without seeing your code, I can only speculate about the problem, but you need
to understand that the script language stack only supports forty concurrent
for/next loops. Chances are, your use of GOTO is the problem: if you GOTO out
of a for/next loop, the loop is not cleared, and remains active. If you have
loops nested three deep, it would not take very long to blow the forty-maximum.
It is important to allow a loop to complete execution; the most appropriate
application of the GOTO statement in this context is to bypass code in a loop
(to run out the loop) as in the following pseudo code example:
for [loop]
if [condition] then GOTO SKIP
[operation]
@SKIP
next [loop]
In general, there are very few appropriate instances for using the GOTO
statement — usually GOSUB is preferable. The above instance is an legitimate
exception.
Hope this helps.
Martin
Martin- Thanks for the info on GOTO and FOR/NEXT. I did not know that the loop
stayed around after it was re-started (as in the nesting scenario). I have
already re-coded the script with no FOR/NEXT (using manual loops) and it works
fine now, but I will use your suggested fix because it is easier to read!
Mike