Quantcast LoTROInterface - View Single Post - Lua Beginner has some questions
View Single Post
  #6  
Unread 06-15-2016, 09:14 AM
Hamkaas Hamkaas is offline
The Wary
 
Join Date: Jun 2016
Posts: 3
Quote:
The first thing I noticed in your code is that you are using SetParent on Window controls.
I see that makes a lot more sense now, i've updated all my code to make sure Window controls stay top level.



Quote:
The Unload handler does not have to be treated like an event handler in that it is not a shared function (no need for AddCallback).
Quote:
so you can now assign your Unload handler by referencing your plugin as "plugin".
Thanks this makes a lot more sense to me now and i'm using your example to execute the RemoveCallback functions.

Quote:
it is better to use a local variable or create it in-line without a variable
Good advice and i'm certainly gonna follow it and think about that more now. I wasn't aware it would take more memory like this and for me it seemed a bit more neat for me this way.

P.S. did you edit this in since when i had less time when i first read your post i did not read this

But now i'm trying to use more Local variables and such i was wondering what is the proper way of using them within a function or something?
for example:
Code:
function DirFlip(DirX,DirY,number,player)
	local x = GetCol(number)+DirX;
	local y = GetRow(number)+DirY;	
	while State[GetNum(x,y)] ~= player do
		Flip(GetNum(x,y));
		x = x + DirX;
		y = y + DirY;
	end
end
In this code i define local variables x and y, but when i update x and y in the while loop does it update the local variables or does it create global x and y variables? I did not put "local" in front of the x and y variables inside the while loop since i would think it would create new local variables only accesable within the while loop.

Quote:
Originally Posted by Thurallor
But I just do it the obvious way, which makes me think I am misunderstanding the question.
Holy shit, no you didn't misunderstand the question. I guess when i tried this before i must have made a different mistake, maybe some typo or something. I tried it copying your code and it totally works! thanks!


Thank you guys so much! I'm really learning a lot from this.
Next time i ask questions i really should try to make myself more clear and also add more of my own code to show what i tried. It was late at night when i wrote this so i guess looking back my post does seem a bit unclear.
Reply With Quote