How do I correct a "const mismatch in out variable"? - unreal-development-kit

So I'm currently writing code to access a player's uniqueNetId using:
Class'GameEngine'.static.GetOnlineSubsystem().UniqueNetIdToString(
OnlineSubsystemSteamworks(Class'GameEngine'.static.GetOnlineSubsystem()).LoggedInPlayerId.Uid);
But that leads to this:
Error, Call to 'UniqueNetIdToString', parameter 1: Const mismatch in Out variable
Does anybody have any idea what I'm doing wrong?

It's not actually a const mismatch. The function is expecting a struct and you are passing in a member of the struct instead. Try removing the .Uid, i.e.:
Class'GameEngine'.static.GetOnlineSubsystem().UniqueNetIdToString(
OnlineSubsystemSteamworks(Class'GameEngine'.static.GetOnlineSubsystem()).LoggedInPlayerId);

Related

How can I store different error interface implementations together and then use them for type comparison in Go?

I'm trying to write a table test in go where the test cases will result in different errors. I then want to check if the type of the error matches a an error type defined in the test case, using errors.As(). Each test case is defined by a struct, so there needs to be a type in the struct that can hold any implementation of the interface error, which is then also to verify that the correct type was returned in the test.
I have tried defining the struct as follows
type testCase struct {
testInput string
expectedError error
}
I also have a number of custom errors that implement the error interface, lets say one is called myCustomError
I then declare a variable of that struct like this:
mTest := testCase{
testInput: "some failing string",
expectedError: myCustomError{},
}
if I then do the test like this...
err := someFunc(mTest.testInput)
if errors.As(err, &mTest.expectedError) {
// test have succeeded
}
... the if statement will always return true, regardless of which of my custom error types is returned.
I made a minimal example if this behavior on the Go Playground here: https://play.golang.org/p/uMdbMvfcdQi
In the playground example, I expect the string "matching myError1" to be printed twice, but instead it also matches myError2 when the value is stored as a plain error before it is used to check the type of the variable err.
Is is even possible to do something like this?
Store a pointer to the target value in the test case.
type testCase struct {
testInput string
expectedError interface{}
}
mTest := testCase{
testInput: "some failing string",
expectedError: &myCustomError{},
}
err := someFunc(mTest.testInput)
if errors.As(err, mTest.expectedError) {
// test have succeeded
}
Minimal example: https://play.golang.org/p/igJy9L_ui73

Reflection: Struct by string

Let's assume I have this struct with a method:
package main
import (
"fmt"
"reflect"
)
type MyStruct struct {
}
func (a *MyStruct) AAction() {
fmt.Println("Hello a")
}
Now, if I want to call the method "AAction" by string, I can use reflection (this works):
func main() {
reflect.New(reflect.TypeOf(MyStruct{})).MethodByName("AAction").Call([]reflect.Value{})
}
The problem is, that I don't want to use MyStruct{} as an expression, but as a string. Of course this doesn't work:
func main() {
theStruct := "MyStruct"
theAction := "AAction"
reflect.New(reflect.TypeOf(theStruct)).MethodByName(theAction).Call([]reflect.Value{})
}
because reflect.Typeof(theStruct) would be a string.
I tried reading through the documentation, sadly, I can't find anything very useful.
I found this similar question: Call a Struct and its Method by name in Go?
Under the accepted question, the OP asks:
The issue in my case Is I cant not declare t is typed T, its must be some how I can declare t typed T by the name of T is string "T"
which gets answered by
[...] I would suggest to match the name against the string "T" somewhere in your code [...]
which doesn't solve the problem, as I would still need to call MyStruct{} somewhere.
The question is: is there any way to use a struct by giving the name as a string? (without manually mapping the the name of the struct to the struct)
Working version with using reflect.TypeOf(MyStruct{}):
PlayGround
Not working version, obviously calling the method on a string: PlayGround
Sorry, you can't. The answer is: you could not. There is no builtin or pre-initialized registry of type names.
To get started with reflection (reflect package), you need a value (of the type in question). Based on a string (string name of the type), you can't acquire a value of that type, so you can't get started.
If you do want to do what you want only by a string type name, you need to build your own "registry" prior to doing what you want.

D: Cannot seem to create an std.container.Array of const struct pointers

Suppose I have a struct type Foo. I'm trying to create an std.container.Array of const pointers to Foo. I tried the obvious first:
import std.container;
alias FooArray = Array!(const(Foo*));
However, this causes a compiler error. Then I tried it with fewer parentheses:
alias FooArray = Array!(const Foo*);
But this gave the same error (error instantiating apparently). What am I doing wrong here?
Array probably needs to modify the reference (if not the object).
Try this:
alias FooArray = Array!(const(Foo)*);

Unexpected reply signature: got "oa{sv}", expected "(oa{sv})"

Using C++/QtDBus.
I'm trying to get a reply from DBus call to function described as:
object, dict PullAll(string targetfile, dict filters).
I registered (qDBusRegisterMetaType) a type defined as: typedef QPair< QDBusObjectPath, QVariantMap > Transfer;
In QDBusPendingCallWatcher handler I'm doing:
QDBusPendingReply<Transfer> reply = *pwatcher;
I get an error:
Unexpected reply signature: got "oa{sv}", expected "(oa{sv})"
What's wrong? What is parentheses in "(oa{sv})"?
I think the whole message needs to be wrapped in a struct. At least you have the proper signature otherwise and are getting a response.
arrays: []
dict entries: {}
structs: ()
I'm not that familiar with QtDbus, but looking at the page for the QDbusArgument Class, you might have to do something like this:
argument.beginStructure();
argument << mystruct.objectpath << mystruct.array;
argument.endStructure();

qRegisterMetaType usage

#include<QMetaType>
typedef QList<int> IntList;
qRegisterMetaType<IntList>("IntList");
error C2909: 'qRegisterMetaType': explicit instantiation of function template requires return type
C2909 says I need to define
template int qRegisterMetaType<IntList>("IntList");
If I define like I mentioned above then I get the below error
error C2059: syntax error : 'string'
warning C4667: 'int qRegisterMetaType(void)' : no function template defined that matches forced instantiation
why do I get this error ?
"qRegisterMetaType" is a function. It must appear in a code block.
int metatype_id = qRegisterMetaType<IntList>("IntList");
You need to add Q_DECLARE_METATYPE(IntList) before you can register it.

Resources