Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to combine Strings$ in Tier 2 C++?

Author
Message
Xaby
FPSC Reloaded TGC Backer
16
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 8th Nov 2019 12:12 Edited at: 8th Nov 2019 13:36
I did not found any information about how to do simple string operations in C++ with App Game Kit.

agk:: Print("Text");

agk:: Print(agk::Str(number));

but how can I make agk:: Print("Text" + agk::Str(number)); ?

It is complecated, if I would have to use a helper uString variable and use MyString.append ... every time, I want to combine a nice string for Print();
Also I don't understand, how delating a string works and why I have to do it.

e.g.: uString myString = "Hallo";

--> but if I have that in the main loop, the memory usage gets bigger and bigger. It seems, that myString will not be overwritten. And how do the Hashtables work or dynamic arrays?
At the moment I am using <vector>, but that is not App Game Kit, that is std-c++

can someone help me or hint in the right direction?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 8th Nov 2019 12:55 Edited at: 8th Nov 2019 12:56
I found this site really useful

https://www.tutorialspoint.com/cplusplus/cpp_date_time.htm

In terms of strings, dont you literally just use +? I.e. string3=string1 + string2
Xaby
FPSC Reloaded TGC Backer
16
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 8th Nov 2019 13:35 Edited at: 8th Nov 2019 13:41
@Santman,

couldn't compile with Visual Studio when using "+" in agk:: Print()

maybe the uString can't handle that. But "const char* MyString = "Hallo1" + "Hallo2"; also does not work. Visual Studio will underline the "Hallo2" with a red line.

and cout << ... would be the console. If you use const char* MyString = "Hallo1" "Hallo2"; that would work, but how can I combine a Print("FPS:") with the ScreenFPS function e.g.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 8th Nov 2019 15:11
Maybe if you grab the screen fps first as a string, then combine them as you've said? I'm not great with T2 but that is something I struggled with too.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 8th Nov 2019 15:55
the strcat (result,string) should append strings in c++ but I think you need to include <string.h>



If for some reason you cant use string.h you will have to make your own function that gets around this
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 9th Nov 2019 06:28 Edited at: 9th Nov 2019 06:57
Just like fubarpk said. The disadvantage of this strcat is that you always have to make sure that there is enough memory in the target string and that you have to think of the terminating zero.

Another solution would be to work with c++ std::string's.

Another solution is to work with formatted strings.


Here number is displayed in decimal and in brackets in hexadecimal.


You can also use the uStrings you mentioned.
As format string.

Or as an appended string.


EDIT:
I have forgotten - If you have received a string with the function agk::??? you must delete this string after using it. (To prevent a memory leak.)


EDIT2:
Xaby wrote: "At the moment I am using <vector>, but that is not App Game Kit, that is std-c++"

std::vector and std::list are very usefull just like std::map.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Xaby
FPSC Reloaded TGC Backer
16
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 9th Nov 2019 10:00
@MadBit, @fubarpk

thx.

The next question would be, how to export that AppGameKit project than to Android, I know, there are tutorials out there for Visual Studio, but they mostly are in C# and or use MonoDevelop.

and that thing with the strings ... puh. That is somewhat hard to believe, because Turbo Pascal could do it, most Basic dialects can do it. C# can do it. Or for Print-output I would use PrintC and Print to avoid that problem.

is map something like a hastable with 2 values and they can have any type? I could e.g. put a string and an integer into it and search for the string and get the integer?
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 9th Nov 2019 19:13
Xaby wrote: "The next question would be, how to export that AppGameKit project than to Android, I know, there are tutorials out there for Visual Studio, but they mostly are in C# and or use MonoDevelop.

and that thing with the strings ... puh. That is somewhat hard to believe, because Turbo Pascal could do it, most Basic dialects can do it. C# can do it. Or for Print-output I would use PrintC and Print to avoid that problem.
"

I am not so well versed in android programming. I can't really help them. But as far as I know you can also use the STL containers there. And if you use uString's the procedure should remain the same.
In the app folder of the AppGameKit installation, there are also Android C++ templates and a tutorial on the AGK_page.
But I think you've seen this before.

Xaby wrote: "is map something like a hastable with 2 values and they can have any type? I could e.g. put a string and an integer into it and search for the string and get the integer?"


Yeah. You can do that, for example.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Xaby
FPSC Reloaded TGC Backer
16
Years of Service
User Offline
Joined: 17th Apr 2007
Location: Berlin
Posted: 9th Nov 2019 21:49
@MadBit

you are my hero.
So a Map doesn't require complecated "add-element" or "insert" operations, if the String is not the same, from what I see in your code.
So the Map is dynamic and does most of the things "alone". Nice

Login to post a reply

Server time is: 2024-03-29 00:56:20
Your offset time is: 2024-03-29 00:56:20