lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
Thread Tools Display Modes
  #1  
Unread 10-04-2010, 10:16 PM
SanDBoX's Avatar
SanDBoX SanDBoX is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Location: Idaho
Posts: 40
issue with functions inside of a class

I recently ran across an issue where when I am defining functions inside of a class I can no longer use the "self" identifier such as:
Code:
10   MyWindow = class( Turbine.UI.Window )
11 
12   function MyWindow:Constructor()
13     Turbine.UI.Lotro.Window.Constructor( self ) --this part works fine
14     self.int = 5
15     ...
16   end
17
18   function MyWindow:BronkenFunction()
19     self.int = self.int + 1 
20   end
Oversimplified but should give the right idea, in this kind of an instance I end up getting an "Attempt to index local self (a 'nil' value)" error, and the thing that bugs me the most is I have functions in other files that work just fine and they are written the same way (outside the constructor)

Any idea what it is that I am missing? This really has me lost tonight...
Reply With Quote
  #2  
Unread 10-04-2010, 11:59 PM
moebius92 moebius92 is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 51
When you call the BronkenFunction(), are you using . or :? I.e.,

myWindow = MyWindow();
myWindow.BronkenFunction();

vs.

myWindow = MyWindow();
myWindow:BronkenFunction();

Because you should be doing the second.
Reply With Quote
  #3  
Unread 10-05-2010, 07:32 AM
SanDBoX's Avatar
SanDBoX SanDBoX is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Location: Idaho
Posts: 40
Okay, that worked, and explains why it was so flacky and only did it when I clicked one button (all the other ways it was called worked fine). Guess I was more tired then I thought last night.

Thank you.
Reply With Quote
  #4  
Unread 10-05-2010, 09:42 AM
Digital_Utopia's Avatar
Digital_Utopia Digital_Utopia is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 207
Send a message via MSN to Digital_Utopia Send a message via Yahoo to Digital_Utopia
Quote:
Originally Posted by SanDBoX
Okay, that worked, and explains why it was so flacky and only did it when I clicked one button (all the other ways it was called worked fine). Guess I was more tired then I thought last night.

Thank you.
If you want to call a function with the common dot operator, create the function like so:

Code:
MyWindow.BronkenFunction = function()
     self.int = self.int + 1 
end
Then you could call it with "MyWindow.BronkenFunction()"
__________________

Lord of the Rings Online
75 Fourohfour | 75 Artemedis | 60 Whiskeytango Foxtrot | 50 Mistah Boombastic | 56 Appetizer | 25 Aggromi
61 Onepointtwentyone Gigawatts


World of Warcraft
90 Downlo 85 Gravetaxi 85 Ümad 85 Artemedis 85 Guthuros
Reply With Quote
  #5  
Unread 10-07-2010, 02:25 PM
Kryso Kryso is offline
The Undefeated
 
Join Date: Oct 2010
Posts: 8
And this example would fail again, because there would be no "self" (or at least no valid self).

Code:
function Table:Foo( arg )
    self.bar= self.bar+ arg;
end
is just syntactic sugar for

Code:
Table.Foo = function( self, arg )
    self.bar = self.bar + arg;
end
and

Code:
Table:Foo( 1 );
is the same as

Code:
Table.Foo( Table, 1 );
Reply With Quote
  #6  
Unread 10-07-2010, 03:29 PM
Bonechip's Avatar
Bonechip Bonechip is offline
The Wary
 
Join Date: Jan 2010
Posts: 1
Cool What I read....

If the inverting-core acceptor deflects the complex chronotron-feedback analysis, try to provoke a coil-composition reflex and several quantum biosphere resonances, this will create a restricted isovolumic cochrane graviton-prediction, which ought to in fact dampen the polarizing maintenance-filament formulas. Then attempt a minimum abstract component-delay correction phase to input a reversible lucifugal primary ionization perimeter operation to cancel the celestial info-sphere greenhouse effect level-limits. As you are doing this, set in motion six homeostasis global-attractors from the constant chemical cybernetic-induction elliptical-beam, this will dislodge a krypton placebo-molecule from the kinetic synthesis-accelerator.

You guys are talking greek. LOL
Reply With Quote
  #7  
Unread 10-07-2010, 04:49 PM
SanDBoX's Avatar
SanDBoX SanDBoX is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Location: Idaho
Posts: 40
LOL not that bad bonechip

Still seams funny to me that LUA has such a flexable syntax, I am usto very defined lines instead of the the whole "you can do it this way, or if you want this way, or this way... " and the fact that it all still works unless you make a dumb mistake is just Icing on the cake.
Reply With Quote
  #8  
Unread 10-07-2010, 09:14 PM
Digital_Utopia's Avatar
Digital_Utopia Digital_Utopia is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 207
Send a message via MSN to Digital_Utopia Send a message via Yahoo to Digital_Utopia
Quote:
Originally Posted by Kryso
And this example would fail again, because there would be no "self" (or at least no valid self).
Well..part of that is a bit of a typo. It should be:

Code:
self.BronkenFunction = function()
    self.int = self.int+1
end
Instead of using MyWindow.
__________________

Lord of the Rings Online
75 Fourohfour | 75 Artemedis | 60 Whiskeytango Foxtrot | 50 Mistah Boombastic | 56 Appetizer | 25 Aggromi
61 Onepointtwentyone Gigawatts


World of Warcraft
90 Downlo 85 Gravetaxi 85 Ümad 85 Artemedis 85 Guthuros
Reply With Quote
  #9  
Unread 10-08-2010, 04:15 AM
Kryso Kryso is offline
The Undefeated
 
Join Date: Oct 2010
Posts: 8
Quote:
Originally Posted by Digital_Utopia
Well..part of that is a bit of a typo. It should be:

Code:
self.BronkenFunction = function()
    self.int = self.int+1
end
Instead of using MyWindow.
Yea this would work if you created the function in another function, so it would take self from parent scope - which is in a lot of cases bad practice, because it would create new function on every call. I mean it is usefull sometimes, but it shouldn't be used so we can call functions that are supposed to have "self" reference with dot operator.
Reply With Quote
  #10  
Unread 10-08-2010, 06:37 AM
Digital_Utopia's Avatar
Digital_Utopia Digital_Utopia is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Sep 2010
Posts: 207
Send a message via MSN to Digital_Utopia Send a message via Yahoo to Digital_Utopia
Quote:
Originally Posted by Kryso
Yea this would work if you created the function in another function, so it would take self from parent scope - which is in a lot of cases bad practice, because it would create new function on every call. I mean it is usefull sometimes, but it shouldn't be used so we can call functions that are supposed to have "self" reference with dot operator.
Except most "class" definitions are technically functions. eg:

Code:
MyWindow = class( Turbine.UI.Window )
function MyWindow:Constructor()
      Turbine.UI.Lotro.Window.Constructor( self )



end
And, given that it isn't a local function, (i.e. something that will never be called from outside the class), wouldn't it make sense to make a unique copy of that function for every instance of the class?
__________________

Lord of the Rings Online
75 Fourohfour | 75 Artemedis | 60 Whiskeytango Foxtrot | 50 Mistah Boombastic | 56 Appetizer | 25 Aggromi
61 Onepointtwentyone Gigawatts


World of Warcraft
90 Downlo 85 Gravetaxi 85 Ümad 85 Artemedis 85 Guthuros
Reply With Quote
Reply


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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
graphics issue Jeremy3020 Interface Help (L) 0 09-21-2010 08:50 PM
Frosty! I cannot reposition any assets inside the Minimap_Window (Radar)! Supermax XML modification help (L) 11 05-27-2009 02:25 PM
Trait Panel Race/Class galenswerd Graphics modification help (L) 4 01-13-2009 12:32 PM
letterbox_bottom xp bar issue Aalwein General Authoring Discussion (L) 2 05-15-2007 08:55 AM
A anoying issue aegget Graphics modification help (L) 5 05-10-2007 06:20 AM


All times are GMT -5. The time now is 08:22 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui