dumb newbie questions
Posted: 07 Jan 2010, 02:20
I've searched my lua directory and can find no files containing the words "sleep" or "wait". There's nothing in the lua guide either. I want to set something on a loop, repeating every second, but I can't figure out what the proper command is to insert a waiting period.
_____
I've got this script here that I made. It resizes my minimap automatically, works perfect, no complaints. I just noticed I never bothered to put a "return" or "return true" or "return false" or any manner of return anywhere in it. It still works though. What effect, if any, will this have?
_____
What's the difference between:
local blabla = 5
blabla = 5
hm? I've noticed people say things like "speedup" but I wonder what things should be made local and what shouldn't, what benefits there are, etc.
_____
I need to track a mouse button being held down. If it's not held down for half a second solid, it does one action. If it's held down for longer, it does another action. Until the button's released, nothing should happen.
The best idea I have to do this goes like this:
widget handler - mouse button down
if mouse button 2 is down then
local mouse2down = clock()
end
widget handler - mouse button up
if mouse button 2 is up then
local mouse2up = clock()
end
local function mousechecker()
if (mouse2down - mouse2up) < 0.5 then
blabla()
else
blablabla()
end
This seems very complicated though. Is there a better way of doing it? I thought about just waiting half a second and doing a check, but that would be influenced by the game's speed and UI shouldn't change like that. Also, you might just check half a second later and find the player holding the button down for something else entirely... so it needs to be solid. Then I thought about doing a few shorter waits, like 5 of them, and if it wasn't held down during any of them, break the count. Seemed kind of excessive.
The fist thing I tried was the simple:
if not (mouse2 down) then...
but this seems to be triggered by other mouse button presses as well, for instance button 0... possibly keyboard inputs even, I didn't try that. The player might also be doing things with the other mouse buttons at the same time, which ruled out some other ideas I had.
_____
I've got this script here that I made. It resizes my minimap automatically, works perfect, no complaints. I just noticed I never bothered to put a "return" or "return true" or "return false" or any manner of return anywhere in it. It still works though. What effect, if any, will this have?
_____
What's the difference between:
local blabla = 5
blabla = 5
hm? I've noticed people say things like "speedup" but I wonder what things should be made local and what shouldn't, what benefits there are, etc.
_____
I need to track a mouse button being held down. If it's not held down for half a second solid, it does one action. If it's held down for longer, it does another action. Until the button's released, nothing should happen.
The best idea I have to do this goes like this:
widget handler - mouse button down
if mouse button 2 is down then
local mouse2down = clock()
end
widget handler - mouse button up
if mouse button 2 is up then
local mouse2up = clock()
end
local function mousechecker()
if (mouse2down - mouse2up) < 0.5 then
blabla()
else
blablabla()
end
This seems very complicated though. Is there a better way of doing it? I thought about just waiting half a second and doing a check, but that would be influenced by the game's speed and UI shouldn't change like that. Also, you might just check half a second later and find the player holding the button down for something else entirely... so it needs to be solid. Then I thought about doing a few shorter waits, like 5 of them, and if it wasn't held down during any of them, break the count. Seemed kind of excessive.
The fist thing I tried was the simple:
if not (mouse2 down) then...
but this seems to be triggered by other mouse button presses as well, for instance button 0... possibly keyboard inputs even, I didn't try that. The player might also be doing things with the other mouse buttons at the same time, which ruled out some other ideas I had.