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 / T2 print command

Author
Message
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 3rd Dec 2012 20:05
Hello, once again I post a pretty basic question about Tier 2.

Im trying to use the print command to print some information, but I have ran into some problems. Mostly because of my limited knowledge in C++ and its way of handeling strings.

right now im trying to print some text and then a variable. In T1 I used to do it like this
.

And when moving to T2 I thought it would be done in the same way. But when I do


I get an error on the second "agk::" saying expected an integer or enum.

This prints my string, but not the variable


if I do something like
it works.

So, what should I do to be able to print variables together with strings.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Dec 2012 21:20 Edited at: 3rd Dec 2012 21:21
The problem with something like this:



is that "Test 1" is constant in memory and returns a const char pointer. agk::Str() also returns char pointer and one thing you can not do in C/C++ is add two pointers.

Here's a solution:


You don't need to include anything extra as uString is appart of the AppGameKit libraries.

Quote: "if I do something like this it works."

I don't recommend programming like that (doesn't work on this end anyway). It doesn't work the way you think it does. Look up pointer arithmetic. What it's actually doing is offsetting the pointer.

Also, whenever creating a pointer, don't leave it uninitialised and then use it because you don't know what it's pointing to. If you can't think of something to assign it to upon declaration, assign it to null.
e.g
char *p = NULL;

I hope this isn't too baffling. C++ takes time to get used to and it's very specific. BASIC is far more lenient than C++ so it takes a while to get used to the strict rules.

If the strings are too much trouble and all you want to do is print them, you can also do this:


Hope this helps.

The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 3rd Dec 2012 21:28
Thanks for the reply, the last version seems like a good solution for now

As for pointers, I still have to look into them some more
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Dec 2012 21:42
Quote: " the last version seems like a good solution for now"

Yeah, it's probably easiest solution.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Dec 2012 00:56
I could say it's cleaner in Pascal, but I'll get shouted at!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL

Login to post a reply

Server time is: 2024-11-24 03:57:36
Your offset time is: 2024-11-24 03:57:36