string operations

Started by somebody, Tue 21/09/2004 01:43:44

Previous topic - Next topic

somebody

just a quick question: why can't strings be manipulated like they can in regular C++ or BASIC with the = and + symbols? having to use StrCopy and StrCat really does get annoying when you're used to just using = and + to assign and concatenate strings. take for example:

mystring = name + " has just found a " + object + " in the " + room;

that 1 line of c++/basic would take one StrCopy and a ton of StrCats in AGS!

also, there are if/else and while loops, but i see no for loops. i know that a for loop can be done with a more compliated while loop, but it's just a lot easier to use for.

Gilbert

Because string implementation is not as simple as you think (pointer related), especially in C-style languages.
Having the ability to assign/compare/etc strings with =/==/etc is probably just a warper in the compiler/interpreter for more complicated stuffs, which probably involves the compiler/interpreter to be written more complicatedly (and more likely to introduce more bugs).

I don't find any problem in using those Str...() functions, once you are familiar with them they're really handy,

Scorpiorus

Quote from: Synneth Relmn on Tue 21/09/2004 01:43:44mystring = name + " has just found a " + object + " in the " + room;

that 1 line of c++/basic would take one StrCopy and a ton of StrCats in AGS!
I'd suggest using a StrFormat function in that case:

StrFormat (mystring, "%s has just found a %s in the %s", name, object, room);

Quotealso, there are if/else and while loops, but i see no for loops. i know that a for loop can be done with a more compliated while loop, but it's just a lot easier to use for.
As you say, a for loop can be workarounded with a while loop and that is why there are no for loops - it's not a high priority feature to add. By the way, making a for-like looping with a while loop is as easy as making it with a for loop:

for (int i=0; i<10; i++) {
Ã,  Ã, ...
Ã,  Ã, ...
}

int i=0;
while (i<10) {
Ã,  Ã, ...
Ã,  Ã, ...
Ã,  Ã, i++;
}

SMF spam blocked by CleanTalk