Sign in to follow this  
Badandy

[C#/JS] Getting SharedData on Client

Recommended Posts

Hi, I'm having issues getting SharedData that is set on the Server (C#) on the client (JS) with getVariable. I currently get "undefined" on the client. I have looked it up many times and now I'm here asking this question. 

The code below outlines the following: The client connects to the server and at this time, its setSharedData. After the command testData is used, it triggers a client side event that fires and prints out the sharedData value. 

Here is my code: 

Server Side (C#):

public void OnPlayerConnected(Client player)
{
  player.SetSharedData("test", "test");
}


[Command("testdata")]
public void CMD_testData(Client client)
{
  client.SendChatMessage("Testing Data on Client!");
  client.TriggerEvent("showData");
}

Client Side (JS):

function showData()
{
	let vartest = mp.players.local.getVariable('test');
	
	mp.gui.chat.push("DATA TEST: "+vartest);
}

mp.events.add('showData',showData);

Any help anyone can give is appreciated. Thank you.

Share this post


Link to post
Share on other sites

After further analysis, I have found out that the C# function "setSharedData" isn't putting data into the key that I specified. I tested that by outputting it on the server and also using "hasSharedData" with that returning false. I was scripting the server side initially with JS but moved the JS files out of the directory. Am I missing anything?

Share this post


Link to post
Share on other sites

After reinstalling the bridge and using the updater.exe again, it now works. Must of been an issue on my part when I set up the bridge. Thank you :)

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.