loop counters... annoying Local variable never used error

Users who are viewing this thread

jik

Knight
I have to admit, I really hate the lack of proper loop structures in the MS...

There are instances where you need to loop a specific number of times, but the counter for the loop (try_for_range,":counter",1,10) is only there to count the iterations.  So when I compile I get the silly error that the var is not used.  Well yes it is.  It is incremented 9 times in my loop.  Does any one know a way to trick the system into not giving silly errors like this?  Anyone know how to structure a proper do...while loop with MS? 

:mad: :mad: :mad: :mad: :mad: :mad: does this drive anyone else crazy :mad: :mad: :mad: :mad: :mad: :mad: :mad:
 
Ah yes, i had a similar problem a while ago.

The problem turned out to be that it creates the variables AFTER it looks for them rather than opposite.
What i had to do was to create the definitions first, then compile.
Then code where i want the variable to be used and compile again.

Then again, i guess it also could be fixed by reordering build_module.bat's list of files to compile.
I have not tried this, and it may get other similar problems with different lines instead.
 
just do something like this

(assign,":counter",0),

(try_begin),
  (le,":counter",10),
  [stuff to do in loop]
  (val_add,":counter",1),
(try_end),


EDIT: nevermind, I was thinking of try_for_agents  :grin:

 
Chel said:
just do something like this

(assign,":counter",0),

(try_begin),
  (le,":counter",10),
  [stuff to do in loop]
  (val_add,":counter",1),
(try_end),


EDIT: nevermind, I was thinking of try_for_agents  :grin:

I was thinking the same thing, but nothing forces the code back to the top.  I ended up making one, something like this:
(assign,":a_end",100),                  ##Should be past possible loop end point
(try_for_range,":a",0,":a_end"),
    (assign,reg13,":a"),                      ##uses local variable ":a", no warning message
    ##Code block to execute here##
    (try_begin),
        (eq,"$while_marker", 1),          ##What ever the condition it is to end the loop (do while $while_marker!=1)
        (assign,":a_end",0),                ##was told this is the only way to end the loop, make the end point equal the start point
    (try_end),

Also, I think I found a way to also make sure that ":a" is used.  I pass it to reg13.

 
Back
Top Bottom