Jump to content

Help with widget!


Recommended Posts

So I want to make (what seems like) a simple widget that simply adds icons on the bottom-left of the screen based on a table in the character's prefab, and updating whenever said table changes.

I managed to get the widget to show up, but I don't know how make the game communicate with it.

I've done quite a bit of in-depth research, but I still don't understand how to go about this.

 

Any help would be very much appreciated, as this is the last thing I need for my mod to be pretty much complete in terms of code.

Link to comment
Share on other sites

Without further context as to where the data is coming from, it's hard to say how to make it communicate with it.

If the data is on the server-side (like components and such) and you want the client to know of them, then either use a Mod RPC to tell the client about the information or if it's simpler like a series of bools then a netvar with a bitmask of your information bits.

If the data is all on the client itself that it wants to access (freely readable), then have the UI widget check: if ThePlayer and ThePlayer.yourtable, and then access the information there.

 

For when the table updates, you'll have a couple of options depending on what you have control over.

If you're the creator of the table, then you can create a couple of wrapper functions to add/remove parts which also tells your UI to update.

If you're not the creator of the table but have access to the table's metatable, then you could hook the metatable for it and create a table proxy to see when new entries are added.

If you're not the creator of the table and don't have access to the table's metatable, then you'll need to poll it with a repeating timer.

  • Like 1
Link to comment
Share on other sites

I'm really sorry, it has been a good while since you posted. So I've tried ThePlayer.table method with a periodic check, as that seemed the simplest to do. Needless to say, that method did not work for me.

I have no idea how to do the other things you have mentioned, so I suppose I'll try to elaborate on the missing context so that maybe you could help. I don't know how specific you need the information, but I'll try to be specific

So the table is stored in (the character prefab) inst.mytable.

Whenever I build specific items, they'll add : inst.mytable["value"] = true

Another item, when built, will reset the table to mytable = { }

And that's how my data is stored/changed.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...