Unity: Javascript callbacks, delegates - callback

I would like to use Player.IO from Yahoo Games Network in my Unity javascript code. PlayerIO provides example project for unity written only in C# so I am having problems with getting the callbacks work.
PlayerIO.Connect description from Player.IO documentation for Unity (available here):
public void Connect (string gameId, string connectionId, string userId, string auth,
string partnerId, String[] playerInsightSegments,
Callback<Client> successCallback, Callback<PlayerIOError> errorCallback)
So how to make these callbacks work?
The following part of the question shows the ways I have already tried, but didn't work.
Firstly I've tried this way (as I know from javascript):
function success(client : Client) {
//function content
}
PlayerIOClient.PlayerIO.Connect(pioGameId, pioConnectionId, pioUserId, pioAuth, pioPartnerId, success, failed);
.
That was not right and I've learned that I should use delegates.
From Unity3D official tutorials (available here), the right use of delegates in JS would be like this (using the Function type):
var successDelegate : Function;
function success(client : Client) {
//function content
}
function Start () {
successDelegate = success;
PlayerIOClient.PlayerIO.Connect(pioGameId, pioConnectionId, pioUserId, pioAuth, pioPartnerId, success, failed);
}
This is causing the following error:
InvalidCastException: Cannot cast from source type to destination type.
Main+$Start$2+$.MoveNext ()
.
After that I've found a topic on Player.IO forum (available here) called Utilizing Player.IO in Unity Javascript. Suggested approach of creating delegates in JS by the author of that topic: go straight to the .Net type and declare them as System.Delegate.
var pioConnectSuccessCallback : System.Delegate;
function success(client : Client) {
//function content
}
function Start () {
pioConnectSuccessCallback = System.Delegate.CreateDelegate(typeof(PlayerIOClient.Callback.<PlayerIOClient.Client>), this, "success");
PlayerIOClient.PlayerIO.Connect(pioGameId, pioConnectionId, pioUserId, pioAuth, pioPartnerId, pioConnectSuccessCallback, pioConnectErrorCallback);
}
This is unfortunately also not working for me, although the guys on the forum present it as a working solution (but it may be outdated).
The error I'm getting:
Assets/Main.js(51,35): BCE0023: No appropriate version of
'PlayerIOClient.PlayerIO.Connect' for the argument list '(String,
String, String, String, String, System.Delegate, System.Delegate)' was
found.
So it seems like Connect method doesn't like System.Delegate as a parameter or those were not initialized well.

The 3rd way is working, the function is expecting 8 parameters and that was why it didn't work for me.

Related

#PathParam: No value being passed

I'm building a REST api using Quarkus and Kotlin. I'm trying to include a path parameter in my function by using the #PathParam annotation. This is what I have:
#GET
#Produces(MediaType.APPLICATION_JSON)
#Path("/{userId}")
fun getUser(#PathParam userId: UUID) : GetUserResponse =
try {
GetUserSuccess(userRepository.find("id", userId))
} catch (e: NotFoundException) {
GetUserFailure(e)
}
Unfortunately I'm getting an error stating that there's no value being passed for parameter value.
I googled some stuff, and most of what I found is about wrong imports. I double checked that part, but I import the correct one: import javax.ws.rs.*, which also includes the PathParam.
Anyone knows what's wrong with this?
The answer would be to change it to:
fun getUser(#PathParam("userId") userId : UUID)
Inspirerd by Paul Samsotha's answer.
Alternatively you could also use the #RestPath annotation from RESTEasy:
fun getUser(#RestPath userId: UUID)

Flutter - Compute: Illegal argument in isolate message : (object is a closure - Function '<anonymous closure>':.)

I am trying to unzip a file with compute as follows.
class FileDownloader{
void downloadCompleteZip(Function(double) listenerFunction){
Map<String, dynamic> map = {
'fileRoot': localPath,
"filePath": completeZipLocalPath,
"listener": listenerFunction,
"unzipPerc": unzipPerc
};
await compute(unzipCompleteZipToDisk, map);
}
}
void unzipCompleteZipToDisk(Map<String, dynamic> params) async {}
When i call the downloadCompleteZip function i get the following error:
Invalid argument(s): Illegal argument in isolate message : (object is
a closure - Function '':.)
My types for variables in map are, String and Function. I think the problem is that im trying to pass a function inside map here:
"listener": listenerFunction,
My downloadCompleteZip function is longer, for the sake of example i simplified it. I really need to pass the listener key as it sends messages to update UI. How may i solve this issue of functions not being able to pass within a map inside compute?
Also, kindly please dont suggest third party lib solutions. I have seen that libs like this can help. I am trying to keep 3rd party dependencies as low as possible.
I had the same problem, the solution is to not pass any function nor an object that has a function as property. Then it should work.

Can't open implementation or declaration of toUpperCase() or toLowerCase() in .dart file in intellijIDEA

using .dart file in Intellij IDEA
clicking F12 to show Declaration or Ctrl+Alt+B to show Implementation are not working for methods toUpperCase() or toLowerCase()
they work fine with roundToDouble() and to round()
any ideas how to fix this ?
Edit : below is a screenshot for someone on youtube who could do it !
enter image description here
Because String is not implemented as part of the SDK but instead are runtime specific (the String class you see in the SDK are just a abstract class). So if you e.g. are compiling to JavaScript you will use another implementation (properly a directly call to the same method in JavaScript).
In VM the String methods are "patched" into the class with this class:
https://github.com/dart-lang/sdk/blob/ea50b03cbee9971a3e3f1cc5c832fc2dfb941654/sdk/lib/_internal/vm/lib/string_patch.dart
But as you can see:
String toUpperCase() native "String_toUpperCase";
String toLowerCase() native "String_toLowerCase";
This two methods are actually implemented by a call into the C++ implementation. So we need to look here: https://github.com/dart-lang/sdk/blob/78df4ac452dd3ba69ac0c78559f6dde51eeeadb2/runtime/lib/string.cc
Where we find:
DEFINE_NATIVE_ENTRY(String_toLowerCase, 0, 1) {
const String& receiver =
String::CheckedHandle(zone, arguments->NativeArgAt(0));
ASSERT(!receiver.IsNull());
return String::ToLowerCase(receiver);
}
DEFINE_NATIVE_ENTRY(String_toUpperCase, 0, 1) {
const String& receiver =
String::CheckedHandle(zone, arguments->NativeArgAt(0));
ASSERT(!receiver.IsNull());
return String::ToUpperCase(receiver);
}
This implementation can be found here: https://github.com/dart-lang/sdk/blob/da9697feb96364360bfaedbb1c661c20bf7a4cb0/runtime/vm/object.cc#L22023
StringPtr String::ToUpperCase(const String& str, Heap::Space space) {
// TODO(cshapiro): create a fast-path for OneByteString instances.
return Transform(CaseMapping::ToUpper, str, space);
}
StringPtr String::ToLowerCase(const String& str, Heap::Space space) {
// TODO(cshapiro): create a fast-path for OneByteString instances.
return Transform(CaseMapping::ToLower, str, space);
}
Where the CaseMapping can be found here: https://github.com/dart-lang/sdk/blob/da9697feb96364360bfaedbb1c661c20bf7a4cb0/runtime/platform/unicode.h#L170
And so on and on... :)

FilterOperator bug in using quotes, same code different behavior across systems/time

this.getView().getModel().read("/QualificationProficiencySet", {
filters: [new sap.ui.model.Filter({
path: "Qobjid",
operator: sap.ui.model.FilterOperator.EQ,
value1: nQObjid
})],
success: function(data) {
that._profData = data.results;
that._oQuickView.setModel(new sap.ui.model.json.JSONModel(that._profData), "proficiencyModel");
// delay because addDependent will do a async rerendering and the actionSheet will immediately close without it.
jQuery.sap.delayedCall(200, that, function() {
that._oQuickView.openBy(oLink);
});
},
error: function(evt) {}
});
nQObjidis of type string - always.
Yesterday on our development system I saw the error
"Invalid parametertype used at function 'eq' (Position: 8)"
I noticed that the filter was appended in the URL without single quotes around the value of nQObjid. Strange because at the moment it's added as the value of the filter operator it's clearly a string. I couldn't find any related issues, but I put a (dirty) workaround in place by doing value1: "'"+nQObjid+"'".
This worked, until today, same system, didn't change the code, but suddenly the quotes are part of the value inside the gateway. So I remove the "'"again and tested, works. Then I transport the solution to production to find out that I now have the same problem on production with "Invalid parametertype used at function 'eq'.. Another user on production does not have this issue, so I'm a bit lost.
Similar issue: new SAPUI5 updat to 1.42 has odata bug "Invalid Parameters...
This may not solve your problem but it's too long for a comment, that's why I am posting it here:
When doing a read request, the framework is making a call to a helper class: V2 ODataModel.js Line #4231
aUrlParams = ODataUtils._createUrlParamsArray(mUrlParams);
The helper class then calls a private method: ODataUtils.js Line #72
return "$filter=" + this._createFilterParams(aFilters, oMetadata, oEntityType);
This private method is doing a bunch of stuff, most importantly calling another private method which is actually building the strings ODataUtils.js Line #128
sFilterParam = that._createFilterSegment(oFilter.sPath, oMetadata, oEntityType, oFilterSegment.operator, oFilterSegment.value1, oFilterSegment.value2, sFilterParam);
One of the first thing this method does is formatting your value, and I guess here is where your problem occurs: ODataUtils.js Line #393
oValue1 = this.formatValue(oValue1, sType);
The formatValue function takes your value and its Edm.Type and depending on that type does different stuff. If your objectId is a string, then it should put single quotes at the beginning and the end: ODataUtils.js Line #468
sValue = "'" + String(vValue).replace(/'/g, "''") + "'";
If the type is undefined or some weird value that UI5 doesn't know, then your value is simply cast to a String (which is probably what happens in your case).
Why is the type undefined or weird? That's where you come in... you have to do a little debugging to find out what the actual values are. If the UI5 code is unreadable you can put sap-ui-debug=true as an URL parameter:
my.sap.system.com:8000/sap/bc/ui5_ui5/sap/ztest/index.html?sap-ui-debug=true
If it's a timing issue (metadata has not been loaded for whatever reasons) then wrapping your code in a Promise might help:
var oModel = this.getView().getModel();
oModel.metadataLoaded().then(function() {
oModel.read("/QualificationProficiencySet", {
// ...
});
}

Getting value with javascript and use it in controller

First of all i am using play framework with scala,
What i have to do is , using the data which i am getting with that function;
onClick: function(node) {
if(!node) return;
alert(node.id);
var id = node.id;
}
So what the question is how i can call the methods from controller with this id ? Since js is client-side but scala works with server-side , i need something creative.
This is the function i need to call from my controller.
def supertrack(id:Long) = Action {
}
I have just found out that i need use ScalaJavaScriptRouting in order to send a ajax request to the server.
For the documentation
http://www.playframework.com/documentation/2.1.1/ScalaJavascriptRouting