Sign In Register

How can we help you today?

Start a new topic
Answered

GS_DAILY code not running as expected (Getting TypeError)

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

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


Answer

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

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.

Hi Jason,


It would be for the server credential, correct.


-Pádraig



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).

 

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.

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 :)

 

Login to post a comment