Saturday, April 21, 2012

delay in lua

Hi

I'm trying to write a mod to output multiple lines of text to the chat channel and was trying to find out a way of putting a delay (say 5 seconds) between each line|||Code:
function ActionButton_OnUpdate()
if (MyAddon_LastTime == nil) then
MyAddon_LastTime = GetTime()
else
if (GetTime() >= MyAddon_LastTime + 5) then

-- Do stuff here every 5 seconds --

MyAddon_LastTime = GetTime()
end
end
end

You have to drive this kind of code by hooking events or use an On_Update from a frame. I use the Blizzard bar function ActionButton_OnUpdate() which is driven MANY times a second.|||Be carefull with using OnUpdate() though... That code is processed multiple times per second, so it needs to be as light as possible.

Better to trigger off of events, but from what you're describing, yes, OnUpdate is your trigger...|||The problem with triggering from events is that you might not get one for more than 5 seconds, or whatever time measurement you want to use. The only way to have complete accuracy ,as far as timing goes, is to use an On_Update. If time accuracy is not important to what you are trying to do then yes, hooking events is the way to go.|||Thanks guys tried the OnUpdate() and it works nicely , will try the OnEvent handler later to see how they compare|||You may want to count passed time yourself using first argument for OnUpdate handler. I didn't check how heavy GetTime implementation is, but addition and getting two variables from local stack is sure to be faster than table lookup (function is in _G) and function call.

BTW, you can hide frame with OnUpdate handler when you no longer need to watch delay to stop receiving updates and nullify any performance penalty and bring it up again when you need it. In that case you wouldn't have to worry about microsavings much.|||A neater timeout function looks like this:


Code:
function fnBGW_OnUpdate(arg1) -- arg1 is in secs so may me small like 0.020s

glb_elapsedTime = glb_elapsedTime + arg1;

if(glb_elapsedTime >= TIME_TICKS) then
glb_elapsedTime = glb_elapsedTime - TIME_TICKS;
fnBGW_TimeOut();
end
end

The argument to OnUpdate is in secs so it may be small 0.020 (50Hz). Arg1 is time elapsed since last call to OnUpdate. This one saves a call to GetTime else it's the same|||I've been trying every timeout method I could find.

The ones posted here do not work in my application.

The GetTime() looked a little closer, but I only need a one time 5 second delay.

Here is was I need to wait 5 seconds before executing.


Code:
function LevelUp_OnEvent(event)
if ( (event == "PLAYER_LEVEL_UP") ) then
playerName = UnitName("player");
levlup = UnitLevel("player");
SendChatMessage("DING! "..playerName.." has reached level "..levelUp.." !", "GUILD", mylang, "");
end
end

This code is getting the level info too fast, and reporting the LAST level not the level gained.

I've used levelup = UnitLevel("player")+1;

as a temporary fix.

But I worry that if used on a slow comp, or lag comes into play it might report the level wrong (one level up).

Would like to just see this wait 5 seconds before execution, then the level info gathered should be the new correct level.|||Quote:








I've been trying every timeout method I could find.

The ones posted here do not work in my application.

The GetTime() looked a little closer, but I only need a one time 5 second delay.

Here is was I need to wait 5 seconds before executing.


Code:
function LevelUp_OnEvent(event)
if ( (event == "PLAYER_LEVEL_UP") ) then
playerName = UnitName("player");
levlup = UnitLevel("player");
SendChatMessage("DING! "..playerName.." has reached level "..levelUp.." !", "GUILD", mylang, "");
end
end

This code is getting the level info too fast, and reporting the LAST level not the level gained.

I've used levelup = UnitLevel("player")+1;

as a temporary fix.

But I worry that if used on a slow comp, or lag comes into play it might report the level wrong (one level up).

Would like to just see this wait 5 seconds before execution, then the level info gathered should be the new correct level.






When the PLAYER_LEVEL_UP event occurs, then the details you need are actually passed as arguments, and the NEW Player level can be found in arg1 so you shouldn't need any delaying mechanism if I have understood the thread (?)...


Code:
function LevelUp_OnEvent(event)
if ( (event == "PLAYER_LEVEL_UP") ) then
local playerName = UnitName("player");
local levlup = arg1;
SendChatMessage("DING! "..playerName.." has reached level "..levelUp.." !", "GUILD", mylang, "");
end
end

Other useful information is passed in the other default args, such as how much Stamina increase they earned that level...

Check out http://www.wowwiki.com/Events_P_(Par...rBank,_Player)

and scroll down to the PLAYER_LEVEL_UP event...

["icon"] = "Circle" help me

I have been messing around working on an add-on for some friends. I am a newb to programming language and am stuck here. for my quest givers and poi's i have been using ["icon"] = "Circle" what I would like is a clear ring similar to what gatherer uses when you mark a node so what would my icon be for that? Please help.

example:

["info"] = "If you are having trouble finding this guy, he wanders around on the top floor of the inn",

["titleCol"] = 13908198,

["icon"] = "Ring",

["title"] = "Innkeeper Thulfram",



The info section pops up on screen when you mouse over it on your mini map or reg map. My problem is using "Circle", or "Ring" creates a opaque symbol over the quest giver on the mini map and you cannot see the default gold dot. Like when you have gatherer and you can see an active node inside the clear circle.|||Download Gatherer and look in the Shaded folder. There you will find several .tga files that Gatherer uses to impose those circles over the minimap.

sqlhelper problem

hey im just instaled mod its looks cool but i get this eror on news page

Warning: mysql_connect(): Unknown MySQL server host 'dbserver' (1) in /home/content/a/t/i/atilla03/html/bp/itemstats/includes/sqlhelper.php on line 30

string(39) "Unable to connect to SQL host: dbserver"

pls help :|

Problems when highlighting text

I've been writing a mod to pull data out of wow onto notepad. To achieve this the mod puts all the data into an edit box from which you can cut and paste to wherever you want.

What I have at the moment is:

GetDataText:SetText(DataList);

GetDataText:SetFocus();

GetDataText:HighlightText();

GetDataDlg:Show();



The highlight seems to cause all the text to become selected because I can then Ctrl-C and then paste somewhere else and that all works fine. But the text is not shown as highlighted.

Even more weirdly if I run the app again the second time I show the EditBox the highlighting is shown. I've been put a ton of debug messages in and it seems to me that what I need to do is on my first pass through, after calling HighlightText() is get an OnCursorChanged event to be triggered for my edit box.

I've tried calling the function within the XML :

<OnCursorChanged>

ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);

</OnCursorChanged>

and that does nothing. So my guess is that it's some default functionality which is part of all edit boxes.

Can I just send an event to my edit box? I cannot find any function that will do that for me.

Or does anyone know of another way round my problem.

I'll be grateful for any help people can offer|||Quote:








I've been writing a mod to pull data out of wow onto notepad. To achieve this the mod puts all the data into an edit box from which you can cut and paste to wherever you want.

What I have at the moment is:

GetDataText:SetText(DataList);

GetDataText:SetFocus();

GetDataText:HighlightText();

GetDataDlg:Show();



The highlight seems to cause all the text to become selected because I can then Ctrl-C and then paste somewhere else and that all works fine. But the text is not shown as highlighted.

Even more weirdly if I run the app again the second time I show the EditBox the highlighting is shown. I've been put a ton of debug messages in and it seems to me that what I need to do is on my first pass through, after calling HighlightText() is get an OnCursorChanged event to be triggered for my edit box.

I've tried calling the function within the XML :

<OnCursorChanged>

ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);

</OnCursorChanged>

and that does nothing. So my guess is that it's some default functionality which is part of all edit boxes.

Can I just send an event to my edit box? I cannot find any function that will do that for me.

Or does anyone know of another way round my problem.

I'll be grateful for any help people can offer






Some random thoughts.... ;)

In other words, I'm not sure why your problem happens, but these are some things I'd be considering...

1.)

Have you tried the SetText and Highlight AFTER the :Show() ?

OR

You could try the SetText after the :Show(), and put the Highlight() in the EditBox's OnUpdate function.... ?

( This relates to the suggestion about the ScrollingEdit_OnUpdate function below... )

2.)

If your EditBox is part of a ScrollChild then I think you do need the XML you mentioned above, but you also need to call a default <OnTextChanged> function and OnUpdate function too ...although if you are only ever filling the edit box via code and the user isn't ever manually editing it then maybe its not important.


Code:


<OnTextChanged>
ScrollingEdit_OnTextChanged();
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate();
</OnUpdate>

3.)

Have you set your EditBox to autofocus="true" ?

It might be worth a try....

4.)

Finally, its just a thought, but have you tried Hiding, and then Showing your EditBox again

to refresh it....based on your comment about the text being highlighted the next time you run it....although this is just me thinking about that autofocus feature again really...|||Thanks for all of those Telic. I've tried them all. No luck I'm afraid, but thanks for the suggestions.

I tried using ResetCursor() today that does send an OnCursorChanged event, but still no joy with the display so back to the drawing board. You may be right in that the ScrollChild could be responsible for updating the selected shading. So I'll try putting all my debug messages there, rather than the edit box, next time I get a chance to play :o)|||Prat displays URLs in a pop up box and the text is highlighted, you could check how it's done there.|||Can I see your entire frames xml?|||Quote:








Can I see your entire frames xml?




It still needs alot of work on the focusing and the like, but I'm hoping that isn't my problem. Anyway here it is:


Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
<!-- Lua Scripts -->
<Script file="GetData.lua"/>

<!-- Frames -->
<Frame name="GetData_MainFrame">
<Scripts>
<OnLoad>
DEFAULT_CHAT_FRAME:AddMessage("Adding Slash XML",1,1,1);
GetData_OnLoad();
</OnLoad>
</Scripts>
</Frame>


<Frame name="GetDataDlg" toplevel="true" parent="UIparent" movable="false" resizable="false" enableMouse="true" hidden="true" enableKeyboard="true" frameStrata="DIALOG">
<Size>
<AbsDimension x="450" y="350"/>
</Size>
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="11"/>
</BackgroundInsets>
<TileSize>
<AbsValue val="32"/>
</TileSize>
<EdgeSize>
<AbsValue val="32"/>
</EdgeSize>
</Backdrop>
<Frames>
<Button name="GetDataButtonClose" inherits="UIPanelButtonTemplate" text="Close">
<Size>
<AbsDimension x="75" y="20"/>
</Size>
<Anchors>
<Anchor point="BOTTOMRIGHT">
<Offset>
<AbsDimension x="-20" y="20"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
GetDataDlg:Hide();
</OnClick>
</Scripts>
</Button>

<ScrollFrame name="GetDataScrollFrame" inherits="UIPanelScrollFrameTemplate">
<Size>
<AbsDimension x="390" y="255"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="18" y="-18"/>
</Offset>
</Anchor>
</Anchors>
<Layers>
<Layer level="ARTWORK">
<Texture name="GetDataScrollBarTop" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
<Size>
<AbsDimension x="31" y="156"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT" relativePoint="TOPRIGHT">
<Offset>
<AbsDimension x="0" y="5"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0" right="0.484375" top="0" bottom="1.0"/>
</Texture>
<Texture name="GetDataScrollBarBottom" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
<Size>
<AbsDimension x="31" y="106"/>
</Size>
<Anchors>
<Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT">
<Offset>
<AbsDimension x="0" y="-2"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0.515625" right="1.0" top="0" bottom="0.4140625"/>
</Texture>
<Texture name="GetDataScrollBarMiddle" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
<Size>
<AbsDimension x="31" y="60"/>
</Size>
<Anchors>
<Anchor point="TOP" relativeTo="GetDataScrollBarTop" relativePoint="BOTTOM">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
<Anchor point="BOTTOM" relativeTo="GetDataScrollBarBottom" relativePoint="TOP">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
<TexCoords left="0" right="0.484375" top=".75" bottom="1.0"/>
</Texture>
</Layer>
</Layers>
<Scripts>
<OnTextChanged>
ScrollingEdit_OnTextChanged(GetDataScrollFrame);
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate(GetDataScrollFrame);
</OnUpdate>
</Scripts>
<ScrollChild>
<EditBox name="GetDataText" autofocus="true" multiLine="true" letters="12000">
<Size>
<AbsDimension x="541" y="234"/>
</Size>
<Scripts>
<OnTextChanged>
ScrollingEdit_OnTextChanged(GetDataScrollFrame);
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate(GetDataScrollFrame);
</OnUpdate>
</Scripts>
<FontString inherits="ChatFontNormal"/>
</EditBox>
<Scripts>
<OnTextChanged>
ScrollingEdit_OnTextChanged(GetDataScrollFrame);
</OnTextChanged>
<OnCursorChanged>
ScrollingEdit_OnCursorChanged(arg1, arg2, arg3, arg4);
</OnCursorChanged>
<OnUpdate>
ScrollingEdit_OnUpdate(GetDataScrollFrame);
</OnUpdate>
</Scripts>
</ScrollChild>
</ScrollFrame>

</Frames>
</Frame>


</Ui>
|||Quote:








Prat displays URLs in a pop up box and the text is highlighted, you could check how it's done there.




hehe on first scan I thought you were insulting me ;o)

I downloaded Prat and gave it a try. Am I right in that the URL pops up in an separate box with just a single line of text. If so I'm not sure it helps. I stole some similar code from Deadly Boss Mods to base mine on. My problem seems to be the volume of text I'm trying to highlight. If I just populate a couple of lines in the edit box they get highlighted fine. But what I'm trying to do involves hundreds of lines of text, the start of which is beyond the top of the scroll box and has scrolled off. I'm wondering if I'm actually trying to get the UI to do something for which it was has never really been tested :o/

K|||Yeah it's just the URL on a single line as you say, ah well figured it was worth mentioning, hope you get it working :) .|||This 'probably' won't help with your problem but just to clarify my earlier point...

The "ScrollingEdit_On..." Scripts only need to be set for the EditBox. (i.e. within the EditBox tags)

Not for the ScrollFrame or the ScrollChild

I'm not sure what the consequences would be of trying to add those scripts to all 3 - it probably just generates FrameXML errors, and skips 'em when not needed...

Anyway, sorry the suggestions didn't help - don't forget to post the solution if you do find one ;)|||Quote:








This 'probably' won't help with your problem but just to clarify my earlier point...

The "ScrollingEdit_On..." Scripts only need to be set for the EditBox. (i.e. within the EditBox tags)

Anyway, sorry the suggestions didn't help - don't forget to post the solution if you do find one ;)




No worries. This wasn't my inention for the final XML, I just went mad (mainly with desparation) and dumped the handler stuff all over the place. Thanks for pointing out that it was still there, I'll take it out again

Thanks for all the help and don't worry if I ever solve the problem I'll let you know

Checking for combat

I was wondering if anyone has any idea on how to determine a) whether or not a player is in combat and if so b) if the unit they are attacking/being attacked by is an npc boss, like an in instance. I'm trying to create an auto-reply system for whispers but I can't get UnitAffectingCombat to work. Sorry if that was confusing, and thanks in advance.|||Quote:








I was wondering if anyone has any idea on how to determine a) whether or not a player is in combat and if so b) if the unit they are attacking/being attacked by is an npc boss, like an in instance. I'm trying to create an auto-reply system for whispers but I can't get UnitAffectingCombat to work. Sorry if that was confusing, and thanks in advance.




There has always been an option in AlphaMap to hide the map during combat, (and re-open it when combat is over).

It does this by monitoring for the "PLAYER_REGEN_DISABLED" and "PLAYER_REGEN_ENABLED" events, and has always seemed pretty reliable to me. I haven't tested what happens when a player has special buffs/abilities that allow some regeneration during combat, but I suspect they will still receive these events.



For determining target details you could try the following :

UnitClassification should report "worldboss", "rareelite", "elite", "rare",........

http://www.wowwiki.com/API_UnitClassification

and

UnitLevel should report -1 when unit is a special boss (whatever that means...)

http://www.wowwiki.com/API_UnitLevel



Other people may have better suggestions :)|||Quote:




UnitLevel should report -1 when unit is a special boss (whatever that means...)




If I remember correctly this means that the target is a "Skull" level monster so it should work for what you're trying to detect here.

For reference, the skull means it pretends to be three levels above you regardless of your level (in terms of hit/resist chances but its health/mana/damage/etc stay the same).|||Not sure if it will work in all situations but I'm currently using InCombatLockdown() to check for combat status.|||I can't remember the name of the mod right now, but there is an answering machine type addon that takes your messages when afk, but also auto-replies to tells during combat. The one I saw replied with the name of the boss you were fighting as well. Anyone remember the name of that mod?|||Thank you for the help, I've managed to detect whether the player is in combat with a boss in order to determine if an auto-reply is needed. I've been working on a few keyboard replacements (eg %HP for Boss Health Percent) but can't seem to get it work right.


Code:
autoreply=string.gsub(autoreply,"$B" , UnitName("target"));
autoreply=string.gsub(autoreply,"$P", UnitName("player"));
autoreply=string.gsub(autoreply,"$HP",((UnitHealth("target")/UnitHealthMax("target"))*100).." %");

Which returns the correct number as a percentage, and allows for other things to be added after it, but the % sign is always mysteriously missing, any ideas?

For example, if you type "$P is fighting $B, who has $HP health left. Try again later."

This is returned: "Dinarin is fighting Pygmy Venom Web Spider, who has 100 . health left. Try again later."|||Since it is a pattern do you need to code it this way, with an extra % sign? Pattern matching confuses me so I am just guessing since % is a "magic" character.


Code:
autoreply=string.gsub(autoreply,"$HP",((UnitHealth("target")/UnitHealthMax("target"))*100).." %%");
|||Yes, you need to escape it somehow, but I'm not certain on how you do that in Lua.|||Quote:








Since it is a pattern do you need to code it this way, with an extra % sign? Pattern matching confuses me so I am just guessing since % is a "magic" character.


Code:
autoreply=string.gsub(autoreply,"$HP",((UnitHealth("target")/UnitHealthMax("target"))*100).." %%");






That did it, thank you very much. Now I just have to make sure my conditions to test for raid/5-man bosses are correct lol.|||I think this is the problem... Some "magic characters" (such as %) have special uses in LUA. These are:

^ $ ( ) % . [ ] * + - ?

To use these in a pattern you have to precede them with a % symbol. So for example, "%%" would match a single %... lol, just saw that Jumpy beat me to this:)

Mod to Suppress Quest Progression Messages

I was wondering if it were at all possible for someone to create (if one is not already made that I am unaware of) a mod to block the Quest Progression Messages that come up. i.e. "Quest Crystals: 5/8" that come up. I am using nQuest Log and like how they're progression text comes up but cannot find a way to turn off the other one.

layers in .lua

Hi,

I have a little issue with my minimap and my UI frames which i have configured using Ten UI mod. Im using lua to make frames and attach frames to minimap, omen, SW damage meters etc. But when im moving my minimap over one of the frames the border is crossing over the minimap. I wonder if i can make a higher layer or priority of the minimap such that it gets over the borders.

Screenshot of the current:

large image of the UI



First time posting on these forums so be gentle :)|||Have fun messing about with frame:SetFrameLevel(level)

Example:


Code:
MyMinimap:SetFrameLevel(100)
|||Figured out the porblem. It was a nasty little addon called Bongos MapBar which caused all the trouble. :)

thank you for the response though