GS_DAILY code not running as expected (Getting TypeError)
J
Jason Tuyen
started a topic
over 5 years ago
I have some code in my GS_DAILY cloud code script that will set some private data for every player in my game to a certain value every day which is shown below:
var player = Spark.getPlayer();
player.setPrivateData("valueThatGetsResetEveryDay", true);
However, I've only just noticed whilst using the NOSQL Explorer that my script isn't running as expected and in fact is actually giving this error:
"TypeError: Cannot call method "setPrivateData" of null"
This would imply that the player object I'm retrieving is supposedly null and I have no idea why or whether I'm actually approaching my code wrong.
Best Answer
C
Customer Support
said
over 5 years ago
Hi Jason,
The GS_DAILY script has no context for the player, and so your player object will always be null in this case.
A solution that might work for you is that in your GS_DAILY script, submit a Bulk-Job Module that will run for every player, which will update the players private data. If a Module is passed into the Bulk Job, this module will have player context (as it will run for every player). You can even stipulate to only update specific players that meet a criteria with a query to the Bulk Job.
The GS_DAILY script has no context for the player, and so your player object will always be null in this case.
A solution that might work for you is that in your GS_DAILY script, submit a Bulk-Job Module that will run for every player, which will update the players private data. If a Module is passed into the Bulk Job, this module will have player context (as it will run for every player). You can even stipulate to only update specific players that meet a criteria with a query to the Bulk Job.
-Pádraig
J
Jason Tuyen
said
over 5 years ago
That definitely sounds like a viable solution and I'll definitely look into it in more detail. Anyway, looking into the documentation for scheduling bulk jobs, do I set the permission for doing that for the server credential or the server-send credential?
Also I just realised for new players the private data value would always be null until midnight when the bulk job runs if I try to look it up so I'll probably add some code (most likely during authentication) to check if the value exists first and create/set that value if it doesn't.
Customer Support
said
over 5 years ago
Hi Jason,
It would be for the server credential, correct.
-Pádraig
J
Jason Tuyen
said
over 5 years ago
Thanks for that. Anyway I'm currently having trouble working out how to set this bulk job up. I've already created my module but I have no idea how to call submitJobModule so it will run for every player (particularly the JSON query part although it's probably more ideal to have it run for every player that has the private data value I made set already and maybe even better if it's already set to a certain value to reduce server overload).
J
Jason Tuyen
said
over 5 years ago
Actually never mind I've worked out how to build the JSON query I need to find every player that has that private data value set.
J
Jason Tuyen
said
over 5 years ago
Quick update on my situation: After some waiting so I could test it, the solution (creating a bulk job) actually worked so I'll be marking that as my answer :)
Jason Tuyen
Hi Jason,
The GS_DAILY script has no context for the player, and so your player object will always be null in this case.
A solution that might work for you is that in your GS_DAILY script, submit a Bulk-Job Module that will run for every player, which will update the players private data. If a Module is passed into the Bulk Job, this module will have player context (as it will run for every player). You can even stipulate to only update specific players that meet a criteria with a query to the Bulk Job.
-Pádraig
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Jason,
The GS_DAILY script has no context for the player, and so your player object will always be null in this case.
A solution that might work for you is that in your GS_DAILY script, submit a Bulk-Job Module that will run for every player, which will update the players private data. If a Module is passed into the Bulk Job, this module will have player context (as it will run for every player). You can even stipulate to only update specific players that meet a criteria with a query to the Bulk Job.
-Pádraig
Jason Tuyen
That definitely sounds like a viable solution and I'll definitely look into it in more detail. Anyway, looking into the documentation for scheduling bulk jobs, do I set the permission for doing that for the server credential or the server-send credential?
Also I just realised for new players the private data value would always be null until midnight when the bulk job runs if I try to look it up so I'll probably add some code (most likely during authentication) to check if the value exists first and create/set that value if it doesn't.
Customer Support
Hi Jason,
It would be for the server credential, correct.
-Pádraig
Jason Tuyen
Jason Tuyen
Actually never mind I've worked out how to build the JSON query I need to find every player that has that private data value set.
Jason Tuyen
-
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