Results 1 to 6 of 6

Thread: Lua Classes... THIS IS EXTREMELY IMPORTANT!!!

  
  1. #1
    CT_Bolt's Avatar
    CT_Bolt is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    With the humans
    Posts
    54
    Rep Power
    14

    Default

    I really need help defining classes very badly. :(

    I know that I need to make a table then, make a function with the table's name, put a colon after the name, and finally type the name of the function (belonging to the class). :posessed:

    e.g:

    Code:
    ClsTest = {tColor = {"red", "green", "blue"}, tNumber = {5, 7, 11}}
    
    function ClsTest:New()
         -- Make a new ClsTest
    end
    For more information: Click Here. ;)

    I need to know how to create a new class of the same name:

    Code:
    ClassA = ClsTest:New()
    ClassB = ClsTest:New()
    The values of ClassA & ClassB (the table value) should be different, but the're allways the same when I do it like this. :mad:

    Please, Please, Help Me Soon. :sigh: I really need to understand this ASAP. :|


  2. #2
    illfoundedmind is offline -Hacks Enthusiast
    Join Date
    Nov 2005
    Location
    WTF~~~~~~~~~~> Rank: %NULL
    Posts
    389
    Rep Power
    14

    Default

    Well then it isn't making a new class it is just overwriting the same one, work around it.
    july 19

  3. #3
    CT_Bolt's Avatar
    CT_Bolt is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    With the humans
    Posts
    54
    Rep Power
    14

    Default

    I have been trying but, I think I got it handled. Thank You for responding though.
    This will hopefully be the last "Help Me" post.

  4. #4
    romero126 is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Posts
    81
    Rep Power
    14

    Default

    Code:
    CLASS = { }
    function CLASS:New(params)
    	-- Define metaTable above.
    	t = params or { }
    	setmetatable(t, CLASS)
    	return t
    end
    
    -- To set your own meta table.
    
    table = { <put data here> }
    		-- Generic table doesnt have to have anything.
    
    MetaTable1 = CLASS:New(table)
    MetaTable2 = CLASS:New(table)
    
    MetaTable1.info = "This is random text"
    MetaTable2.info = "Glaaarrrrrr"	-- This will be different than MetaTable1

  5. #5
    CT_Bolt's Avatar
    CT_Bolt is offline -Hacks Neophyte
    Join Date
    Jan 2006
    Location
    With the humans
    Posts
    54
    Rep Power
    14

    Default

    Oh... sry I posted this awhile ago and I now wrote my own class tutorial. ;)
    My Class Tutorial: Click Here

    Thanks for responding though. :)

  6. #6
    Yenman007 is offline -Hacks Member
    Join Date
    Feb 2006
    Location
    fire
    Posts
    214
    Rep Power
    14

    Default

    thx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •