ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Simple Question about code. (https://www.esoui.com/forums/showthread.php?t=1121)

zireko 04/23/14 04:49 PM

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.

Iyanga 04/23/14 05:15 PM

http://wiki.esoui.com/MyFirstAddon_tutorial

zireko 04/23/14 05:20 PM

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.

Errc 04/23/14 05:36 PM

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.

Joviex 04/23/14 05:46 PM

Quote:

Originally Posted by zireko (Post 5563)
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.

Iyanga 04/24/14 10:13 AM

Quote:

Originally Posted by zireko (Post 5568)
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/

ingeniousclown 04/24/14 10:29 AM

I think the "easiest" method would be to just type "/fps" in your chat window...

archpoet 04/24/14 11:20 AM

I agree with each of the replies in their own way.

OP should take one of the provided outs. ;)

BadVolt 04/24/14 02:25 PM

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 ;)

Seerah 04/24/14 08:48 PM

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.


All times are GMT -6. The time now is 12:10 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI