Thread Tools Display Modes
10-16-19, 05:04 AM   #1
sh4dowburn
A Murloc Raider
 
sh4dowburn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2019
Posts: 8
Question [Classic]LF help with LUA

Hi everyone!

I'm trying to write my first AddOn about showing my total money and latency in game,
But I notice that the total amount and latency only updated after input "/reload" in game now,

here is my code,
Code:
local m = CreateFrame("Frame", nil, UIParent);
      m:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -88, 6);
      m:SetWidth(80);
      m:SetHeight(10);
      m:RegisterEvent("PLAYER_MONEY");
      m:RegisterEvent("PLAYER_ENTERING_WORLD");

local Getmoney = GetMoney();
      money = m:CreateFontString(Getmoney, nil, nil);
      money:SetAllPoints(m);
      money:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE");
      money:SetJustifyH("LEFT");
      money:SetTextColor( 1, 1, 1 );
      money:SetFormattedText(("%d|cffFFD700g|r ".." %d|cffB5B5B5s|r ".." %d|cffCD853Fc|r"):format(Getmoney /10000, (Getmoney / 100) % 100, Getmoney % 100));
Code:
local bandwidthIn, bandwidthOut, latencyHome, latencyWorld = GetNetStats();

  local l = CreateFrame("Frame", nil, UIParent)
        l:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -21, 6)
        l:SetWidth(80)
        l:SetHeight(10)
        l:RegisterEvent("PLAYER_ENTERING_WORLD")

        latency = l:CreateFontString(latency, nil, nil)
        latency:SetAllPoints(l)
        latency:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")

        --latency:SetShadowOffset(1, -1)
        --latency:SetShadowColor(0, 0, 0, 1)

        latency:SetJustifyH("RIGHT")
        latency:SetTextColor( 1, 1, 1 )
        latency:SetFormattedText(latencyHome.."/"..latencyWorld.."|cff87CEEB ms")
I'm new to Lua, learn all above codes from wowwiki and blizz source codes.
  Reply With Quote
10-16-19, 06:10 AM   #2
Urtgard
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 25
You need an event handler and you must tell the frame to use this handler.

Lua Code:
  1. local frame = CreateFrame("FRAME", "FooAddonFrame");
  2. frame:RegisterEvent("PLAYER_ENTERING_WORLD");
  3. local function eventHandler(self, event, ...)
  4.  print("Hello World! Hello " .. event);
  5. end
  6. frame:SetScript("OnEvent", eventHandler);
https://wow.gamepedia.com/Handling_events

To update the latency you maybe need an OnUpdate script.
  Reply With Quote
10-16-19, 06:20 AM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Latency data is updated somewhere around every 30 seconds to a minute. An OnUpdate for that is completely unnecessary. I suggest registering a regular event to update latency, such as UNIT_AURA or COMBAT_LOG_EVENT_UNFILTERED. Make sure this event only calls for latency, doing more with these events is a potential performance hit in combat.
  Reply With Quote
10-20-19, 12:41 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Kanegasi View Post
Latency data is updated somewhere around every 30 seconds to a minute. An OnUpdate for that is completely unnecessary. I suggest registering a regular event to update latency, such as UNIT_AURA or COMBAT_LOG_EVENT_UNFILTERED. Make sure this event only calls for latency, doing more with these events is a potential performance hit in combat.
Using events to update something that isn't related to is generally a bad idea. There are a ton of issues that happen depending on which data you're trying to access or even trying to update your output in a timely manner. There is no single or group of events that is guaranteed to fire every X seconds in all situations.

A more direct alternative to using OnUpdate is the C_Timer lib. C_Timer.NewTicker() wraps a function you give it and repeatedly calls C_Timer.After(). See SharedXML\C_TimerAugment.lua for Blizzard's implementation.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-20-19 at 12:47 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [Classic]LF help with LUA

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off