Thread Tools Display Modes
03/09/14, 07:14 PM   #1
Shinni
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 167
A bunch of beginner LUA questions

I wrote a little script to help me add map pins.
However, this is my first time working with LUA and while understanding other scripts works fine, writing "blind" is kinda hard.
I can't test my script without a beta, so there are probably a bunch of errors in it.
There are some sections where I am really unsure whether they work (see bottom of this post).
Feel free to read the whole script, though. There are probably other errors i couldn't find.
(You may also correct my English, if I made some mistakes. I don't mind improving in another language besides LUA )

complete script:
Warning: Spoiler


1)
Does this delete the entry with the key pinTag, or will the key be associated with the value nil?
(The former implies the later but will pairs(self.pins[pinType]) yield (pinTag, nil) or is it completely removed from the table?)
Lua Code:
  1. self.pins[pinType][pinTag] = nil

2)
radius = radius gives me headaches...I'm really unsure about this. (Line 42)
Lua Code:
  1. pins[pinTag] = { area = subzone, x = locx, y = locy, radius = radius }

3)
At first, pinTooltipCreator is a string, but then its assigned to a table.
What happens with AddLine(pinTooltipCreator)? What's the application order of LUA?
Will it add the string because when the function was defined, pinTooltipCreator was still a string?
...or will it crash because when the function is executed, pinTooltipCreator is a table?
Lua Code:
  1. if type(pinTooltipCreator) == "string" then
  2.     pinTooltipCreator = { creator = function(pin) InformationTooltip:AddLine(pinTooltipCreator) end, tooltip = InformationTooltip }
  3. end

4)
The function is defined and called inside methods of two different objects. Will self represent the defining or the executing object?
Lua Code:
  1. function( g_mapPinManager )
  2.     for pinTag, pin in pairs(self.pins[pinType]) do
  3.         --only draw pin, if player is on the correct map
  4.         if pin.zone = GetMapName() then
  5.             if pin.radius then
  6.                 g_mapPinManager:CreatePin( pinType, pinTag, pin.x, pin.y, pin.radius )
  7.             else
  8.                 g_mapPinManager:CreatePin( pinType, pinTag, pin.x, pin.y )
  9.             end
  10.         end
  11.     end
  12. end

Last edited by Shinni : 03/10/14 at 11:25 AM. Reason: fixing some errors
  Reply With Quote
03/09/14, 08:07 PM   #2
Pawkette
 
Pawkette's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 20
You wanna call

Lua Code:
  1. self:CreatePinType

Key being the colon instead of a period, also Create instead of create. Colon signifies self being passed invisibly to the function.

foo:Bar() == foo.Bar( self )

Will keep reading

Last edited by Pawkette : 03/09/14 at 08:10 PM.
  Reply With Quote
03/10/14, 11:39 AM   #3
Shinni
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 167
Thanks, I fixed the mentioned errors.
Using : instead of . is kinda new to me. I've rarely seen a : in other languages.
  Reply With Quote
04/03/14, 07:35 AM   #4
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Lua indeed has some nice benefits.

http://www.lua.org/pil/5.html
Lua also offers a special syntax for object-oriented calls, the colon operator. An expression like o:foo(x) is just another way to write o.foo(o, x), that is, to call o.foo adding o as a first extra argument. In Chapter 16 we will discuss such calls (and object-oriented programming) in more detail.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » A bunch of beginner LUA questions


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