How to create any Request method, that I will be call multiple times from the script ? For example, let's take getPropertyRequest() and create simple method:
public void getGSProperties(string shortCode, int state)
{
new GameSparks.Api.Requests.GetPropertyRequest().SetPropertyShortCode(shortCode).Send((response), =>
{
if (!response.HasErrors)
{
Debug.Log("'" + shortCode + "' received from server");
GSData target = response.Property;
}
else
{
Debug.Log ( "Error Getting '" + shortCode +"' from server");
}
});
}
GetPropertyRequest using Action<GetPropertyResponse> delegate, which cannot return response property from the lambda expression. Secondly, i'ts worked, if we assign variable locally, but I can't create universal method, because lambda expression doesn't support OUT and REF params, so we can't create method with reference parameter, for ex: public void getGSProperties(string shortCode, ref GSData target).
How to create 1 method for getPropertyRequest (or any other request methods), which can return received value to the script ?
Best Answer
C
Customer Support
said
over 6 years ago
Hi Maxim,
Would the following sample of code help in what you're trying to achieve?
public void GetLevelItems(string levelName, Action<IEnumerable<ItemModel>> onLevelItemsReceived)
{
new GameSparks.Api.Requests.LogEventRequest_getLevelItems()
.Set_levelName(levelName)
.Send((response) =>
{
if (response.HasErrors) return;
onLevelItemsReceived(ModelFactory.CreateLevelItemTransferModel(response));
});
}
As you can see what I'm doing here is passing in an Action that can then be called once a response have received.
Hope this helps,
- Steve
1 Comment
Customer Support
said
over 6 years ago
Answer
Hi Maxim,
Would the following sample of code help in what you're trying to achieve?
public void GetLevelItems(string levelName, Action<IEnumerable<ItemModel>> onLevelItemsReceived)
{
new GameSparks.Api.Requests.LogEventRequest_getLevelItems()
.Set_levelName(levelName)
.Send((response) =>
{
if (response.HasErrors) return;
onLevelItemsReceived(ModelFactory.CreateLevelItemTransferModel(response));
});
}
As you can see what I'm doing here is passing in an Action that can then be called once a response have received.
Maxim Samsonov
Hello,
How to create any Request method, that I will be call multiple times from the script ?
For example, let's take getPropertyRequest() and create simple method:
GetPropertyRequest using Action<GetPropertyResponse> delegate, which cannot return response property from the lambda expression. Secondly, i'ts worked, if we assign variable locally, but I can't create universal method, because lambda expression doesn't support OUT and REF params, so we can't create method with reference parameter, for ex: public void getGSProperties(string shortCode, ref GSData target).
How to create 1 method for getPropertyRequest (or any other request methods), which can return received value to the script ?
Hi Maxim,
Would the following sample of code help in what you're trying to achieve?
As you can see what I'm doing here is passing in an Action that can then be called once a response have received.
Hope this helps,
- Steve
Customer Support
Hi Maxim,
Would the following sample of code help in what you're trying to achieve?
As you can see what I'm doing here is passing in an Action that can then be called once a response have received.
Hope this helps,
- Steve
-
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 2487 topics