[SOLVED] String to string - or "ouxx is a dumbass"

Started by Monsieur OUXX, Thu 22/07/2010 11:03:15

Previous topic - Next topic

Monsieur OUXX

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
Code: ags

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.
 

GarageGothic

I'm guessing that the problem isn't strings vs. Strings but rather the extra "}" bracket before the return.

Monsieur OUXX

Oh I forgot a braccket after "else". Problem solved!
 

Monsieur OUXX

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 :

Code: ags

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"



 

Joe

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...
Copinstar © Oficial Site

Dualnames

#5
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. 
         
Code: ags
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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Monsieur OUXX

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
 

SMF spam blocked by CleanTalk