I am trying to get a very simple example working. I want every minute to send a message to all the players.
So I modified the cloude code of the system event GS_MINUTE with this:
var players = Spark.getPlayerIds();
Spark.sendMessageById({"TEST" : "DTC"}, players);
Then in unity I have an object with the following script attached:
public class TEST : MonoBehaviour
{
void Awake()
{
ScriptMessage.Listener = (ScriptMessage message) =>
{
Debug.Log("We just got a ScriptMessage");
};
GSMessageHandler._AllMessages = (GSMessage e) =>
{
Debug.Log("ALL HANDLER " + e.MessageId);
};
}
}
But I do not get any printout in the console. I also tried to put the cloud code in an event and to trigger it from the testharness, but without more success.
Best Answer
C
Customer Support
said
almost 7 years ago
Hi Stephanie,
Good catch. Yes, the getPlayerIds() method is specific for the Global Message Cloud Code. Though you're use of it is correct, it will not work in this context because EVERY_MINUTE will not have Player context whereas Global Message has global Player context.
What you'll need is a context of the player's external to it - the following post should prove useful in setting this up. https://support.gamesparks.net/discussions/topics/1000070846
Also, what exactly were you planning on sending every minute? We strongly recommend you avoid sending messages in the EVERY_MINUTE script.
I still have this issue. I managed to send messages to the users in other pieces of cloud code, but I do not seem to be able to do so in the EVERY_MINUTE and EVERY_DAY codes. Well, at least nothing is received in Unity. I'm not sure if there is a way to check if something was fired from GS server.
That is probably not an error in the script, as I was mentioning the test harness do not cry and the code is trivial:
var players = Spark.getPlayerIds();
Spark.sendMessageById({"TEST" : "DTC"}, players);
I noticed the cloud code I used is now marked as deprecated. I changed it to this,
var players = Spark.getPlayerIds();
var msg = Spark.message(null);
msg.setPlayerIds(players);
msg.setMessageData({"type" : "MinuteUpdate", "Message":"This is a minute update."});
msg.send();
but it is still the same: I do not get anything on Unity's side, neither in the editor nor deployed on a device.
S
Stephane Lallee
said
almost 7 years ago
Actually I think I found what is the issue here, I added this line to my cloud code to be able to inspect the content of the variables:
var players = Spark.getPlayerIds();
var msg = Spark.message(null);
msg.setPlayerIds(players);
msg.setMessageData({"type" : "MinuteUpdate", "Message":"This is a minute update."});
msg.send();
Spark.setScriptData("Debug.PlayersIDs", players)
It turns ou in the inspector that the response is the following (the player list is empty.):
Good catch. Yes, the getPlayerIds() method is specific for the Global Message Cloud Code. Though you're use of it is correct, it will not work in this context because EVERY_MINUTE will not have Player context whereas Global Message has global Player context.
What you'll need is a context of the player's external to it - the following post should prove useful in setting this up. https://support.gamesparks.net/discussions/topics/1000070846
Also, what exactly were you planning on sending every minute? We strongly recommend you avoid sending messages in the EVERY_MINUTE script.
Thanks,
Vinnie
S
Stephane Lallee
said
almost 7 years ago
Hi Vinnie,
Thanks for the pointer. Indeed I managed to have it working with maintaining my own collection.
Actually I'm going to have this script executed every hour.
I am just putting it in every minute to make it easier to debug. The idea is to update some decaying values that are stored against each player, and warn them when they are too low.
Thank you again,
Stephane
Customer Support
said
almost 7 years ago
Hi Stephane,
Glad that it's working for you.
That's fine, there shouldn't be an issue with running that hourly. Please contact us if you need any further assistance.
Vinnie
T
Tanner Brooks
said
about 5 years ago
Hello,
I have a very similar setup but am still having a hard time figuring out the player id array to send to all players. I have a runtime collection storing player names and ids (playerCollection) but I can't figure out how to extract just the ID part of the documents to set the player ID array. Can anyone help?
Stephane Lallee
Hi,
I am trying to get a very simple example working. I want every minute to send a message to all the players.
So I modified the cloude code of the system event GS_MINUTE with this:
Then in unity I have an object with the following script attached:
But I do not get any printout in the console. I also tried to put the cloud code in an event and to trigger it from the testharness, but without more success.
Hi Stephanie,
Good catch. Yes, the getPlayerIds() method is specific for the Global Message Cloud Code. Though you're use of it is correct, it will not work in this context because EVERY_MINUTE will not have Player context whereas Global Message has global Player context.
What you'll need is a context of the player's external to it - the following post should prove useful in setting this up. https://support.gamesparks.net/discussions/topics/1000070846
Also, what exactly were you planning on sending every minute? We strongly recommend you avoid sending messages in the EVERY_MINUTE script.
Thanks,
Vinnie
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Stephane,
Can you paste the inspector log from the test harness please.
Might help us narrow down the cause.
Thanks,
Oisin
Stephane Lallee
I don't think that it will be very informative:
Stephane Lallee
Up.
I still have this issue. I managed to send messages to the users in other pieces of cloud code, but I do not seem to be able to do so in the EVERY_MINUTE and EVERY_DAY codes. Well, at least nothing is received in Unity. I'm not sure if there is a way to check if something was fired from GS server.
That is probably not an error in the script, as I was mentioning the test harness do not cry and the code is trivial:
Customer Support
Could you try....
GameSparks.Api.Messages.ScriptMessage.Listener = (message) =>
{
Debug.Log("We just got a ScriptMessage");
};
Please let us know if that works.
Thanks,
Sean
Stephane Lallee
Does not seem to change anything.
I noticed the cloud code I used is now marked as deprecated. I changed it to this,
but it is still the same: I do not get anything on Unity's side, neither in the editor nor deployed on a device.
Stephane Lallee
Actually I think I found what is the issue here, I added this line to my cloud code to be able to inspect the content of the variables:
It turns ou in the inspector that the response is the following (the player list is empty.):
Customer Support
Hi Stephanie,
Good catch. Yes, the getPlayerIds() method is specific for the Global Message Cloud Code. Though you're use of it is correct, it will not work in this context because EVERY_MINUTE will not have Player context whereas Global Message has global Player context.
What you'll need is a context of the player's external to it - the following post should prove useful in setting this up. https://support.gamesparks.net/discussions/topics/1000070846
Also, what exactly were you planning on sending every minute? We strongly recommend you avoid sending messages in the EVERY_MINUTE script.
Thanks,
Vinnie
Stephane Lallee
Hi Vinnie,
Thanks for the pointer. Indeed I managed to have it working with maintaining my own collection.
Actually I'm going to have this script executed every hour.
I am just putting it in every minute to make it easier to debug. The idea is to update some decaying values that are stored against each player, and warn them when they are too low.
Thank you again,
Stephane
Customer Support
Hi Stephane,
Glad that it's working for you.
That's fine, there shouldn't be an issue with running that hourly. Please contact us if you need any further assistance.
Vinnie
Tanner Brooks
Hello,
I have a very similar setup but am still having a hard time figuring out the player id array to send to all players. I have a runtime collection storing player names and ids (playerCollection) but I can't figure out how to extract just the ID part of the documents to set the player ID array. Can anyone help?
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics