LoTROInterface

LoTROInterface (https://www.lotrointerface.com/forums/index.php)
-   Lua Programming Help (L) (https://www.lotrointerface.com/forums/forumdisplay.php?f=50)
-   -   Real basic help (https://www.lotrointerface.com/forums/showthread.php?t=1337)

Gramps 12-29-2010 05:05 PM

Real basic help
 
Hey there, I've been spending some time digging around the Turbine examples and basically want to learn how to do really simple lua.

If I wanted to learn how to say, make a simple Window, maybe add in a button or two, maybe add a function to a button. Where would I start?

I just have some time on my hands and thought I could spend some of it on very basic Lotro LUA stuff. If this is something that time, effort and a learning capacity cant overcome, and school is the only route then be honest :D

Thx.

SanDBoX 12-29-2010 05:46 PM

Lua is an extreamly flexable language which is easy to learn (hurts the head if you are a c-type programmer already) but you can create a window with only a handful of lines, the hard part (for me atleast) was figuring out how to get lotro to "see" the plugin, for that you can create your own directory with the other plugins and "steal" the .plugin file then rename and modify it (with a text editor or IDE if you have one) then just a matter of making another directory (with your plugin's name). after that you create two files (or three if you plan to have an single place to put your imports) your "main.lua" and your "window.lua" files, in your window file you put in basic code like this -
Code:

import "Turbine"
import "Turbine.UI"
import "Turbine.UI.Lotro"

Window = class( Turbine.UI.Window )

function Window:Constructor()
    Turbine.UI.Lotro.Window.Constructor( self )
    self:SetVisible( true )
   
    --I Setup Window Data
    self:SetSize( 200, 150 )
    self:SetBackColor( Turbine.UI.Color() )
    self:SetPosition( 25, 150 )
    self:SetText( "Hello World!" )
end

that will give you a very basic small window, then in your main.lua file put -
Code:

import <your directory name>.Window

window = Window()

at that point it would just be a matter of digging through the API documentation to get whatever elements/widgets you want to use. there are a lot of examples you can use since you can just open up any of the existing plugins and read them! (I have done that to figure a lot of things out like saving/loading data.)

hope that is a good enough primmer to get you going!

MrJackdaw 12-29-2010 07:55 PM

I found looking at other peoples plugins and working through http://www.lua.org/pil/1.html helped. I still don't understand everything, but learning on-the-job is the best way to learn anything! Well... except brain surgery...

Gramps 12-30-2010 03:19 AM

Quote:

Originally Posted by SanDBoX (Post 5961)
Lua is an extreamly flexable language which is easy to learn (hurts the head if you are a c-type programmer already) but you can create a window with only a handful of lines, the hard part (for me atleast) was figuring out how to get lotro to "see" the plugin, for that you can create your own directory with the other plugins and "steal" the .plugin file then rename and modify it (with a text editor or IDE if you have one) then just a matter of making another directory (with your plugin's name). after that you create two files (or three if you plan to have an single place to put your imports) your "main.lua" and your "window.lua" files, in your window file you put in basic code like this -
Code:

import "Turbine"
import "Turbine.UI"
import "Turbine.UI.Lotro"

Window = class( Turbine.UI.Window )

function Window:Constructor()
    Turbine.UI.Lotro.Window.Constructor( self )
    self:SetVisible( true )
   
    --I Setup Window Data
    self:SetSize( 200, 150 )
    self:SetBackColor( Turbine.UI.Color() )
    self:SetPosition( 25, 150 )
    self:SetText( "Hello World!" )
end

that will give you a very basic small window, then in your main.lua file put -
Code:

import <your directory name>.Window

window = Window()

at that point it would just be a matter of digging through the API documentation to get whatever elements/widgets you want to use. there are a lot of examples you can use since you can just open up any of the existing plugins and read them! (I have done that to figure a lot of things out like saving/loading data.)

hope that is a good enough primmer to get you going!


Thx for the start man. I got the game to 'see' my plugin. "Testwindow" but it wont load :D

TestWindow.lua
Code:

import "Turbine"
import "Turbine.UI"
import "Turbine.UI.Lotro"

Window = class( Turbine.UI.Window )

function Window:Constructor()
    Turbine.UI.Lotro.Window.Constructor( self )
    self:SetVisible( true )
   
    --I Setup Window Data
    self:SetSize( 200, 150 )
    self:SetBackColor( Turbine.UI.Color() )
    self:SetPosition( 25, 150 )
    self:SetText( "Hello World!" )
end

_init_.lua
Code:

import "Gramps.Window.TestWindow";
main.lua
Code:

import "Gramps.TestWindow"

window = Window()


D.H1cks 12-30-2010 07:26 AM

Quote:

_init_.lua
Code:

import "Gramps.Window.TestWindow";

I think the problem is you are pointing to an incorrect path. Do you have a subfolder called Window in your Gramps folder? Let me explain...

I am gonna guess that your .plugin file points to Gramps.TestWindow.main.

Which then looks in the Gramps\TestWindow\main.lua file and sees that it needs to load the Gramps.TestWindow folder, which means the _init_.lua file. So that file looks for the following file: Gramps\Window\TestWindow.lua.

So this would mean you have the following folder layout:

Gramps
  • TestWindow.plugin
    TestWindow
    • _init.lua
      main.lua
    Window
    • TestWindow.lua.

At least, that is what I can gather. If you have the TestWindow file in the same folder as the rest, then simply change the line in the _init_.lua file to:

import "Gramps.TestWindow.TestWindow";

Hope that makes sense.

Gramps 12-30-2010 01:10 PM

Makes perfect sense thanks man.

Making progress.

.d of the Rings Online\Plugins\Gramps\Window\Main.lua:2: Unable to resolve package "Gramps.TestWindow".

I'll dig around a bit and see what I can find out. I honesty spent several hrs yesterday looking though author's plugins, turbine examples, editing turbine examples ect. Thx for the help!


Problem was in my Window.Plugin (pluginsfile) Changed package to Testwindow from Window.

the Rings Online\Plugins\Gramps\TestWindow\main.lua:4: attempt to call global 'Window' (a nil value)
Rings Online\Plugins\Gramps\TestWindow\Main.lua:2: Failed to import package "Gramps.TestWindow.main".

Two new ones now. I'll continue to dig :D

Got it :D

Thx man. You really got me motivated to dig into this stuff.


All times are GMT -5. The time now is 05:30 PM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI