Sorata_Kanda Posted January 10, 2019 Author Share Posted January 10, 2019 59 minutes ago, IIYAMA said: Yes, elementData should be considered as something similar to attributes. <race title="example" /> It defines the specifications of elements. Before you continue, rendering based on elements is not the method with the most performance. So keep that in mind. But! The benefits: There is less (validation- and maintenance)code required. If an element is deleted, then you do not have to clean it from a table. 100% control serverside. Client elements can be set as children of server elements. So these can be auto cleaned as well. The tables from the queries are formatted as arrays, so looping through them doesn't require much time. The rendering happens only when you're near the Race elements. So that shouldn't be a problem? But I still need to have a reference to the object when looping through Race elements. And as far as I found out, they don't update either. Link to comment
Discord Moderators Pirulax Posted January 11, 2019 Discord Moderators Share Posted January 11, 2019 I'm more than sure that on(Client)ElementDataChange is async. 1 Link to comment
Moderators IIYAMA Posted January 11, 2019 Moderators Share Posted January 11, 2019 11 hours ago, Sorata_Kanda said: The rendering happens only when you're near the Race elements. So that shouldn't be a problem? But I still need to have a reference to the object when looping through Race elements. And as far as I found out, they don't update either. Keep in mind that a table should not be a part of a race element. Because tables become a new object when they are saved inside of elementData. But a race element can be a part of a table. There is a function called isElement after all. Another way to reference from a raceElement to a table is by using another table. They should be both in the same environment. reference = {} table = {} element = [[...]] reference[element] = table 5 hours ago, Pirulax said: I'm more than sure that on(Client)ElementDataChange is async. The event system is indeed async. 1 Link to comment
Sorata_Kanda Posted January 11, 2019 Author Share Posted January 11, 2019 (edited) 16 minutes ago, IIYAMA said: Keep in mind that a table should not be a part of a race element. Because tables become a new object when they are saved inside of elementData. But a race element can be a part of a table. There is a function called isElement after all. Another way to reference from a raceElement to a table is by using another table. They should be both in the same environment. reference = {} table = {} element = [[...]] reference[element] = table The event system is indeed async. So as I thought, I won't be coming around with storing those objects in a table. I probably have to fill those reference tables at resource start + with event or something. (Aside: Imagine having those objects "stored" in MySQL. I sort of try to avoid double queries for those Race elements as I think it's not necessary) Edited January 11, 2019 by Sorata_Kanda Link to comment
Sorata_Kanda Posted January 11, 2019 Author Share Posted January 11, 2019 1 hour ago, Sorata_Kanda said: So as I thought, I won't be coming around with storing those objects in a table. I probably have to fill those reference tables at resource start + with event or something. (Aside: Imagine having those objects "stored" in MySQL. I sort of try to avoid double queries for those Race elements as I think it's not necessary) So I sort of managed it like this -- Server races = {} addEventHandler('onResourceStart', resourceRoot, function() -- Query all races from DB for _, race in ipairs(queryResult) do local raceObject = Race.new(race) races[raceObject:getElement()] = raceObject end addEventHandler('onPlayerJoin', resourceRoot, function() triggerClientEvent(source, 'raceUpdateClientTable', this, races) end) end) -- Client races = {} addEvent('raceUpdateClientTable', true) addEventHandler('raceUpdateClientTable', resourceRoot, function(raceTbl) for _, race in pairs(raceTbl) do attachRaceClasses(race) -- See @IIYAMA's example end races = raceTbl end) Any suggestions for improvements? Link to comment
Moderators IIYAMA Posted January 11, 2019 Moderators Share Posted January 11, 2019 (edited) @Sorata_Kanda The event 'onPlayerJoin' triggers faster than a client has loaded his client resources. onClientResourceStart > triggerServerEvent > races > triggerClientEvent This also works for clients that are already in the server. Edited January 11, 2019 by IIYAMA Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now