Multi-threading table help

I’m trying to write to a table made in the main thread in a actor thread

Ex:

Script under a actor
_G.table[reference] = data

table is nil even though i synchronized the thread before hand, I’m not sure what I need to do entirely. Any help is appreciated.

More code would help but I would say to make sure the table is initialized before any of the threads try accessing it. If that’s not it, maybe the synchronization might not be setup correctly.

post code work is now: REDACTED

probs best to create a function to change the main table then pass that function pointer to each actor so they can then use it to call the function when they want to update the table…

You’re unable to do that as it’s loading a different function pointer to a different thread

image

umm save the table as a Value object and read it from that? or can you update the main table by merging all the return values from the actor threads?

how would i get the return values from the actor threads?

apparently bindable events work for this, but I feel like there’s a better way to do it

There are multiple different ways, but bindable events are the most simple option to obtain data back from threads. Also, when I tested _G with multithreading, I got the same issue with not being able to get data in the thread. I think _G cannot be accessed between actors. What I would do is send a second variable in named worldStructures instead of retrieving it through _G.

Edit: I just realized you tried doing that, I would try to put the needed functions in the actor script and retrieve it from there. Probably not the best but it would work.

I attempted to send a function that would allow me to add to the table (thought this hacky solution would work, it did not)
sending it as the current table could work, but it would just lead me back to using bindable events which if i remember correctly can slow down cause of intense bandwith, correct me if im wrong though

also, _G is a new table in every actor, but I thought synchronizing back to the main thread would get me back the _G, but it did not which is unfortunate :frowning:

Bindable Events would not cause lag by networking. Your thinking about Remote Events. Remote Events are used for server/client or client/server communication, while bindable events are used for scripts from server/server or client/client communication.

Sending a function through wouldn’t work, and would just error like above. Could you put a copy of the function in the actors and use it from there? That might work, but I’m not sure if you need the function in the other script or not.

1 Like

If bindable events work, and aren’t causing networking lag then yeah it works fine and can set the main table by firing it in the actor, best part is that they can run parallel as well.

thank you for the help.

EDIT: further testing and bindable events didn’t effect performance at all and if it did, it was very minimal, got 50k structures loading in <5 seconds. i appreciate everyone who postedhere for the help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.