I have not done much work with LUA metatables and have a question. If I need to access data that a metatable has, how should I network the data to the client?
It depends on how the meta-table is coded, it depends on which meta-table, etc...
If you write your own meta-table such as for playing cards. If the meta-table is set up in such a way that you can create new copies of the object with a different value ( so a playing card for all playing cards ) and include a way to pass in the value of the playing card to either re-create the card on the client or to show the value etc via a number, then send the number.
( In this, creating all the cards isn't needed, it is there to show as an example that they are their own object after calling New. This is coded so you can pass in 0-51 for the first deck for cards, and even go to a second or x number of decks by increasing to 52 to x, then x to x+52 etc.. The number can be sent and then viewed without creating objects )
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/classes/class_card.lua.html[/url]
If you write a language table and you want the client to receive a message and have it translated into their own language then send the language key ( #garry or garry and have your language net-receiver process the language then pop it up in notification or whatever ) for the client to process instead of networking the client language and end up sending a much longer string.
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/classes/class_language_new.lua.html[/url]
The way I do the language is to network it: networking:Broadcast( "Notification", NOTIFY_HINT, "#clearedvehicles_log", _count ); -- My custom networking wrapper, basically it takes the args and compiles it into a net-message sending the data as defined in a template ( so Notification uses the type of notification as a number/int 8, the message whereby if it has # it gets translated by user or without it uses as is, then extra args... Extra args are if it is a string.Formated language so it can pass in the additional data )
It really depends on what you're trying to do, specifically...
If you are writing your own meta-table and need help with what everything does:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/classes/class_tutorial.lua.html[/url]
If you use __index ( which is called any time the data is accessed such as table[x] ) make sure to use rawget/set otherwise it'll continue calling.
__newindex is called when data changes or is added, use rawget/set
__call is when the meta-table is called like a function, so table( )
Thank you sir, you have been a great help and going to restructure some of my metatable now.
Sorry, you need to Log In to post a reply to this thread.