question

Joao Amorim avatar image
Joao Amorim asked

Client GrantCharacterToUser in corona sdk does not return a response

local function createChar(result)


    local createCharRequest = {
        CharacterName = charCreation.charName,
        SessionTicket = mySessionTicket,
        ItemId = "charcreation1"
    }
    PlayFabClientApi.GrantCharacterToUser(createCharRequest, onSuccessCreateCha	 r, onErrorCreateChar)


end


local function onSuccessCreateChar(result)
    print("it was success")
end

local function onErrorCreateChar(error)
    print("creation of char Failed: " .. error.errorMessage)
end

------------------------------------------------

So with the code presented above, the character is created and granted to the user correctly, but it doesn't get back any response (error or success). Why does it happen? I've made other kind of requests  (user login, user creation) in the same way and they worked fine.
Characters
1 comment
10 |1200

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

Joao Amorim avatar image Joao Amorim commented ·

the line 9 of the code was supposed to be:

PlayFabClientApi.GrantCharacterToUser(createCharRequest, onSuccessCreateChar, onErrorCreateChar)

I accidently added some spaces while posting this question

0 Likes 0 ·

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

In our testing, PlayFab Corona SDK works fine. The reason that caused this issue is the syntax of Lua. The function definition in Lua needs to be placed before the function call. Because the definition of function in Lua is essentially variable assignment, i.e.

function test() ... end

equals to

test = function () ... end

Therefore, calling the function before the function definition is equivalent to using the variable before the variable assignment. So onSuccessCreateChar and onErrorCreateChar cannot be executed. The following code is the sample that can work fine. Besides, you don’t need to pass SessionTicket in the request body of GrantCharacterToUser. As the API reference shows, it needs to be contained in the request header. And PlayFab SDK will cache it automatically after you log the player in.

If you have more advanced questions about Lua syntax, please refer to Lua’s documentation or contact Lua’s supports for professional assistance.

...

local function onSuccessCreateChar(result)
    print("it was success")
end

local function onErrorCreateChar(error)
    print("creation of char Failed: " .. error.errorMessage)
end

local function createChar(result)
    print("Creating...") 
    local createCharRequest = {
        --SessionTicket = mySessionTicket,
        CharacterName = "TestChar",     
        ItemId = "Blue Warrior"
    }
    PlayFabClientApi.GrantCharacterToUser(createCharRequest, onSuccessCreateChar, onErrorCreateChar)
end

local loginRequest = {
    -- See the API reference for LoginWithCustomID.--
    CustomId = "GettingStartedGuide",
    CreateAccount = true
}
PlayFabClientApi.LoginWithCustomID(loginRequest, createChar, onErrorCreateChar)
...
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.

Error rendering WebPanel (widgets/consolidation-widget.ftl): org.hibernate.hql.internal.ast.QuerySyntaxException: AvailableConsolidation is not mapped [from AvailableConsolidation up where up.node = :node]