Page 1 of 1

not loading new Paths in a loop or if statement

Posted: Tue Jan 31, 2012 7:20 pm
by Rickster
for example (pseudo code)

Code: Select all

count = 0;
while (true) do
	if count > 10 then
		loadPaths(wp_file);
	end;
	print(count);
	count++;
end;
expected behaviour:
when count is greater than 10 wp_file should be loaded and executed

whats happening
MM shows that wp_file has been loaded, but than executes the print statement and continues the loop, showing again and again that the new wp_file has been loaded and prints out "count" which than is greater than 10.

I tried this

Code: Select all

count = 0;
while (true) do
	if count > 10 then
		loadPaths(wp_file);
		error("Stop",0);
	end;
	print(count);
	count++;
end;
which ended up in MM showing that "wp_file" has been loaded, then breaks.
I expected the wp_file to be loaded and never reach the error statement.

I had this prob several time and thought it was a mistake in my coding ... maybe you can point it out to me.

How can i get MM to stop all things from the actual WP file when loading a new one.

Re: not loading new Paths in a loop or if statement

Posted: Tue Jan 31, 2012 8:10 pm
by kkulesza

Code: Select all

	if count > 10 then
		loadPaths(wp_file);
		break;
	end;
Suggested reading -> http://www.lua.org/pil/4.4.html

Re: not loading new Paths in a loop or if statement

Posted: Wed Feb 01, 2012 6:09 am
by Rickster
Reading confirmed ;)

This little "break" was the solution. Thanx!

Re: not loading new Paths in a loop or if statement

Posted: Wed Feb 01, 2012 7:26 am
by rock5
Does ++ work in lua? I wasn't aware.

Re: not loading new Paths in a loop or if statement

Posted: Wed Feb 01, 2012 7:41 am
by lisa
I generally do

Code: Select all

count = count + 1

Re: not loading new Paths in a loop or if statement

Posted: Wed Feb 01, 2012 9:47 am
by Rickster
rock5 wrote:Does ++ work in lua? I wasn't aware.
i dont know, have not tested it. it was just kinda pseudo code to describe the prob, not a real working snippet.

Re: not loading new Paths in a loop or if statement

Posted: Wed Feb 01, 2012 4:50 pm
by Administrator
rock5 wrote:Does ++ work in lua? I wasn't aware.
Nope. That should give a syntax error.

Re: not loading new Paths in a loop or if statement

Posted: Fri Feb 03, 2012 8:45 pm
by MiesterMan
Offtopic, but is it possible to overload operators in lua? (I'm guessing not)