question

brendan avatar image
brendan asked

Cloud Script response gets a MultipletypeError (MultiTypeVar) error in Cocos2d-x

Question from a developer:

I'm calling a Cloud Script that returns a pretty complex JSON object. I'm using the Cocos2d-x SDK, and I'm getting back a MultipletypeError response. What causes this?

CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

This is due to an old concept that we've since replaced in most SDKs - the MultiTypeVar. This was designed as a generic way to handle complex objects, but simply put, it never completely solved that case. The way to solve this is to just change your return to be a string. So instead of

return theBigObject;

go with this:

return JSON.stringify(theBigObject);

Then, you would use RapidJSON (part of Cocos2d-x) to deserialize the string and get your object.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.