Sign In Register

How can we help you today?

Start a new topic

CloudCode error on line 1

I am trying to follow a tutorial on how to update player inventory but at the first steps to get items from a metacollection I get an error saying that the attribute is undefined and the error triggers on line 1

Hi Arno, 

This is general down to either a bad query, r an inappropriate reference to said query. hence the value being undefined or null. 

Could you double check that your query is searching the correct collection and attempting to acquire the correct field o object under a valid key? 

If you can't figure it out feel free to paste the query and data schema you are attempting to query from here. 

Happy to help- Patrick.

 This is the cloud code I had to put in according to the tutorial linked here

// ====================================================================================================
// Cloud Code for getItems, write your code here to customize the GameSparks platform.
// For details of the GameSparks Cloud Code API see
// ====================================================================================================
var type = Spark.getData().type;
if(type !== "")
    Spark.setScriptData('items', Spark.metaCollection('items').find({ "type" : type }, { "_id" : 0}));
    Spark.setScriptData('items', Spark.metaCollection('items').find({}, { "_id" : 0}));


This is the error I getimage

This is the Event I have:


 JSON used to put into item collection:

{  "shortCode" : "hearthstone",  "name" : "Hearth Stone",  "description" : "Transports the user to their home", "type" : "item" }

Hi Arno, 

This is in fact not an error. The debugger is displaying your type variable as undefined because that line has not been executed yet, therefore the value is unassigned. 

Once you step through your cloud code it should assign the variable a vale of the input passed into the request attribute. 

Happy to help - Patrick.

Login to post a comment