node sdk - how do get the player object, set changes?
R
Robert Lombardo
started a topic
almost 5 years ago
Hi there -
In the API docs I see a spec for the player object, but the node sdk doesn't have a Spark object (i think), and i don't see request classes for these... how is this done?
Thanks,
--Rob
Best Answer
C
Customer Support
said
almost 5 years ago
Hi Robert,
I'm going to share the solution provided through the ticketing system here as it may prove valuable to other users...
Normally these types of actions would be done through custom events. For example, you could create an event called 'ExpUp' that increases the player's experience by a set amount. Then add an attribute to this event, let's call it 'amountGained'. Now, in the cloud code for this event, you can use this figure to increase the player's experience, something like:
var player = Spark.getPlayer();
//this assumes the player's script data has a field called 'exp' tracking the player's experience
var exp = player.getScriptData("exp");
exp += Spark.getData().amountGained;
player.setScriptData("exp", exp);
//if you want to return the new value in your response
I'm going to share the solution provided through the ticketing system here as it may prove valuable to other users...
Normally these types of actions would be done through custom events. For example, you could create an event called 'ExpUp' that increases the player's experience by a set amount. Then add an attribute to this event, let's call it 'amountGained'. Now, in the cloud code for this event, you can use this figure to increase the player's experience, something like:
var player = Spark.getPlayer();
//this assumes the player's script data has a field called 'exp' tracking the player's experience
var exp = player.getScriptData("exp");
exp += Spark.getData().amountGained;
player.setScriptData("exp", exp);
//if you want to return the new value in your response
Then you can define how to handle your response and/or error in the callback functions specified.
Regards,
Vinnie
R
Robert Lombardo
said
almost 5 years ago
Again, thanks so much for your help - excellent product, excellent service :)
C
Christopher Weight
said
almost 4 years ago
Hi guys, I'm implementing a password reset solution - currently we are emailing a user with a token (as per your tutorial), I'm just updating this so we email a link to a page we host that provides a form the user fills in with a new password, then sends the final reset request to Gamesparks from there, currently this is a MEAN stack service using the NodeJS Server SDK / API.
BUT this always returns a NULL response from Gamesparks, I'm connecting using the API Key for the app and the 'server-send' credential as the secret - this credential appears to be the only one that connects and initalises the NodeJS API correctly on our service.
Can you explain why I'm getting a null response at all?
Robert Lombardo
Hi there -
In the API docs I see a spec for the player object, but the node sdk doesn't have a Spark object (i think), and i don't see request classes for these... how is this done?
Thanks,
--Rob
Hi Robert,
I'm going to share the solution provided through the ticketing system here as it may prove valuable to other users...
Normally these types of actions would be done through custom events. For example, you could create an event called 'ExpUp' that increases the player's experience by a set amount. Then add an attribute to this event, let's call it 'amountGained'. Now, in the cloud code for this event, you can use this figure to increase the player's experience, something like:
var player = Spark.getPlayer();
//this assumes the player's script data has a field called 'exp' tracking the player's experience
var exp = player.getScriptData("exp");
exp += Spark.getData().amountGained;
player.setScriptData("exp", exp);
//if you want to return the new value in your response
Spark.setScriptData("exp", exp);
//or Spark.setScriptData("playerData", player.getScriptData("exp"));
To call this function from nodejs you'd use:
gameSparks.sendAs(playerId, "LogEventReqest", {"eventKey":"expUp", "amountGained":50}, onExpUp, onExpUpError);
Then you can define how to handle your response and/or error in the callback functions specified.
Regards,
Vinnie- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Robert,
I'm going to share the solution provided through the ticketing system here as it may prove valuable to other users...
Normally these types of actions would be done through custom events. For example, you could create an event called 'ExpUp' that increases the player's experience by a set amount. Then add an attribute to this event, let's call it 'amountGained'. Now, in the cloud code for this event, you can use this figure to increase the player's experience, something like:
var player = Spark.getPlayer();
//this assumes the player's script data has a field called 'exp' tracking the player's experience
var exp = player.getScriptData("exp");
exp += Spark.getData().amountGained;
player.setScriptData("exp", exp);
//if you want to return the new value in your response
Spark.setScriptData("exp", exp);
//or Spark.setScriptData("playerData", player.getScriptData("exp"));
To call this function from nodejs you'd use:
gameSparks.sendAs(playerId, "LogEventReqest", {"eventKey":"expUp", "amountGained":50}, onExpUp, onExpUpError);
Then you can define how to handle your response and/or error in the callback functions specified.
Regards,
VinnieRobert Lombardo
Again, thanks so much for your help - excellent product, excellent service :)
Christopher Weight
Hi guys, I'm implementing a password reset solution - currently we are emailing a user with a token (as per your tutorial), I'm just updating this so we email a link to a page we host that provides a form the user fills in with a new password, then sends the final reset request to Gamesparks from there, currently this is a MEAN stack service using the NodeJS Server SDK / API.
I'm sending a password reset request like so:
BUT this always returns a NULL response from Gamesparks, I'm connecting using the API Key for the app and the 'server-send' credential as the secret - this credential appears to be the only one that connects and initalises the NodeJS API correctly on our service.
Can you explain why I'm getting a null response at all?
Cheers!
Chris
-
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 2485 topics