Thread Tools Display Modes
04/23/14, 04:49 PM   #1
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
Simple Question about code.

I simply want to ask how I would get the frame rate to display in a small window? I currently have this small lua and I'm just trying to call a function. This is my first thing and I'm trying to play around with a very very simple addon. My lua code is listed below.

Lua Code:
  1. function GetFramerate(number)
  2. end

This is the only line of code I currently have and I'm not getting any lua error or anything. But it is not displaying anywhere. Do I need to make a frame for it to display in? If so how would I do that easy methods only please.
  Reply With Quote
04/23/14, 05:15 PM   #2
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
http://wiki.esoui.com/MyFirstAddon_tutorial
  Reply With Quote
04/23/14, 05:20 PM   #3
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
I have already done the tutorial. It is not very good at explaining how the lua works. I've been asking for youtube video tutorials for creation of a few simple mods and explanations of how things are working. The tutorial on wiki seems more for people that already know how to code.
  Reply With Quote
04/23/14, 05:36 PM   #4
Errc
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 30
If you have really done the tutorial then you would know that your code doesn't do anything... You declare a function and nothing else.

Take the tutorial and get that working, then modify parts of it to see what happens. Look at lua help online and try different things with the tutorial to see what breaks and what happens.

There is a ton of similar threads of "How do I code" on these forums, look for them.
  Reply With Quote
04/23/14, 05:46 PM   #5
Joviex
 
Joviex's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 42
Originally Posted by zireko View Post
I simply want to ask how I would get the frame rate to display in a small window? I currently have this small lua and I'm just trying to call a function. This is my first thing and I'm trying to play around with a very very simple addon. My lua code is listed below.

Lua Code:
  1. function GetFramerate(number)
  2. end

This is the only line of code I currently have and I'm not getting any lua error or anything. But it is not displaying anywhere. Do I need to make a frame for it to display in? If so how would I do that easy methods only please.
The code above wont do anything because all you are doing is defining a new function called GetFramerate(paramter = number)


What you want to do is "CALL" the function GetFramerate, not re-define it.


e.g.


fps = GetFramerate()
d(fps)


will display the framerate in the console.


For "constant" updating you would need to hook a callback, so, periodically it would call whatever function you want to perform some action, like, getting the framerate every 100 milliseconds, etc...


If you want to display it on more than the console output, yes, you would need to make a "frame" for it.
  Reply With Quote
04/24/14, 10:13 AM   #6
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by zireko View Post
I have already done the tutorial. It is not very good at explaining how the lua works. I've been asking for youtube video tutorials for creation of a few simple mods and explanations of how things are working. The tutorial on wiki seems more for people that already know how to code.

Yes, that's a reasonable prerequisite.

How the language itself works can be found here for example:
http://www.lua.org/manual/5.2/
  Reply With Quote
04/24/14, 10:29 AM   #7
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
I think the "easiest" method would be to just type "/fps" in your chat window...
  Reply With Quote
04/24/14, 11:20 AM   #8
archpoet
Cunning Linguist
 
archpoet's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 19
I agree with each of the replies in their own way.

OP should take one of the provided outs.
  Reply With Quote
04/24/14, 02:25 PM   #9
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
Instead of blaming creator you can just point him to right direction.

So. To make your addon work you must have at least 3 files:
  1. *.txt
  2. *.xml
  3. *.lua

txt contains information about your addon with addon file list.
xml contains your addon structure anu UI.
lua contains lua code.

So, 1st of all you need to initialize it.

There are several ways of doing it.
1: initialise through xml
2. initialise through event

Both ways are serving one purpose: initialise your addon, but have some difference in use.
When initialising through xml you will have to create TopLevelWindow and link it to event named OnInitialized. It has attribute: self. You do not need it now, beacuse this addon do not use methods. ("Self" will be a reference to object, this function was triggered from)
When initialising through lua you will have to link your addon to event EVENT_ADD_ON_LOADED. It's a little harder, so you can read it yourself here.

In this example we will initialise through XML.

<GuiXml>
<TopLevelWindow name="SuperAddonTopWindow">
<OnInitialized>
AddonStart(self)
</OnInitialized>
</TopLevelWindow>
</GuiXml>

So, when your XML file (part of it) is loaded, this function (AddonStart) will be called from lua file.
Now you can save this xml file and start lua.

1st of all, you need to create function, you want to call from your xml file: AddonStart.

There are several ways to do it:
1st:
Lua Code:
  1. function AddonStart()
  2. end
2nd:
Lua Code:
  1. AddonStart=function ()
  2. end

I prefer 1st one.

So, let's place some cool stuff incide this function.

Lua Code:
  1. function AddonStart()
  2. --you wont see this text, because it will be shown before player chat sreen loads. Btw, this is comment :)
  3. --and "d()" will display some text to the chat
  4. d("Addon Started!")
  5. SLASH_COMMANDS["/showfps"] = ShowFpsHandler
  6. end

We just registered you addon command. When you enter "/showfps", ShowFpsHandler() function will be called. It will say to the game, what to do next.

Lua Code:
  1. function ShowFpsHandler(text)
  2. if text =="" then
  3.    -- ".." allows you to unite text and variable. "tostring" converts any value to text.
  4.    -- Now define local variable and make it equal to result of ingame function GetFramerate()
  5.    -- It is already implemented by developers and allowed to use :)
  6.    local CurrentFps=GetFramerate()
  7.    d("Current Fps: "..tostring(CurrentFps))
  8. else
  9.    d("What? There's no such command! Go away!")
  10. end

Now, you have to make working addom from all this stuff

Last edited by BadVolt : 04/24/14 at 02:37 PM.
  Reply With Quote
04/24/14, 08:48 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Just as an FYI, you do not need an XML file. If your addon does not have any graphical elements, or you choose to create them via the Lua code instead, you can skip it and do everything in just the Lua file.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Simple Question about code.

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