Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Monsieur OUXX on Thu 22/07/2010 11:03:15

Title: [SOLVED] String to string - or "ouxx is a dumbass"
Post by: Monsieur OUXX on Thu 22/07/2010 11:03:15
Hi all,

I know the type "string" is obsolete but I'm using it with AGS 2.72 for the even-more-obsolete-but-ireplaceable TCP plugin 0.0.3 by a-v-o.

How to convert String to string ?

I tried the function below

string S_to_s(String str){
string buffer;
if (str.Length > 255) {
DisplayErr(String.Format("String '%s' is too long to be converted to old-style type 'string'", str));
StrCopy(buffer, "");
} else
StrCopy(buffer, str);
}
return buffer;
}


But it won't compile. Error Parse error: Unexpected 'return'   on line "return buffer;"

I'm puzzled.
Title: Re: String to string
Post by: GarageGothic on Thu 22/07/2010 11:08:01
I'm guessing that the problem isn't strings vs. Strings but rather the extra "}" bracket before the return.
Title: Re: String to string
Post by: Monsieur OUXX on Thu 22/07/2010 11:35:56
Oh I forgot a braccket after "else". Problem solved!
Title: Re: [SOLVED] String to string - or "ouxx is a dumbass"
Post by: Monsieur OUXX on Thu 22/07/2010 11:48:40
IMPORTANT NOTE :
Even after fixing the "else", this function remains flawed by design
"buffer" is a local variable and cannot be returned due to the design of the old "string" type.

A working version would be :


int S_to_s(string s, String str){
//string buffer;
if (str.Length > 255) {
DisplayErr(String.Format("String '%s' is too long to be converted to old-style type 'string'", str));
StrCopy(s, "");
return CODE_ERROR;
}

StrCopy(s, str);
return CODE_OK;
}

//SNIPPET:
String myFancyString;
string my_old_string;

myFancyString = "my fancy string";

S_to_s(my_old_string, myFancyString);
display(my_old_string);


...However the benefit of this new version is tiny compared to the built-in "StrCopy"



Title: Re: [SOLVED] String to string - or "ouxx is a dumbass"
Post by: Joe on Thu 22/07/2010 12:13:23
Did you try it? because I really think that last version wouldn't work since the 'string s' should be declared as a pointer but I don't know if you can declare that kind of variable as a pointer...
Title: Re: [SOLVED] String to string - or "ouxx is a dumbass"
Post by: Dualnames on Thu 22/07/2010 13:19:09
Also ouxx? When you decide to join the IRC again, rog will tell you that it can be ported actually to 3.0.
Sorry, I thought you'd come by again, I tried it shortly after you left, and it works without any quirks. At least nothing obvious.

EDIT: The variable processing can be a bitch btw. 
         StrCopy(old type string, new type String); As you have correctly coded.

It becomes a real problem when you need to process commands via a textbox. Like /join , ecc. I'm actually getting quite accustomed to it. I used to spend a lot of time in AGS 2.72, and yes it can be a pain in the ass, but honestly after a week or so, you feel like a god. It just gives me that feeling.
Title: Re: [SOLVED] String to string - or "ouxx is a dumbass"
Post by: Monsieur OUXX on Thu 22/07/2010 14:49:11
Quote from: Dualnames on Thu 22/07/2010 13:19:09
Also ouxx? When you decide to join the IRC again, rog will tell you that it can be ported actually to 3.0


We'll discuss that on IRC