0 votes

I am trying to integrate some c++ code into the engine.

I get

error C2440: 'initializing': cannot convert from 'std::string' to 'Variant'

Obviously the parameters and return type for my class are std::string. How do I change them so that I can use Variant?

in Engine by (52 points)

1 Answer

+1 vote

Godot doesn't uses STL, and has no clue about what std::string is. You should use the String class provided by Godot. If you can't, try converting your_std_string.c_str() in a String instead.
It also has to be converted because Godot uses wchar_t characters, which are 2-bytes long. std::string has 1-byte characters. If you still want to use the STL, std::wstring might be easier to work with.

by (29,120 points)

Is their an example of how to use the string type?

Well, everywhere in the engine :)
It's a pretty straightforward class, it has concatenation, copy, find, substring etc.
It should be available if you already included variant.h in your C++ file.
You can have a look at the header: https://github.com/godotengine/godot/blob/master/core/ustring.h

So to use it in the module I just need to
1)replace std::string with String
2) remove the #include

3) Then use the ascii method to get a vector of chars to work with. (I think the class I am including only handles ascii)

4)Create a new String with the resulting data.

(It appears that their is already a function for the other code sha256_text().

Thank you for your help. I will try it out when I get time,

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.