String append problems

Started by Theme, Sun 16/10/2005 14:21:12

Previous topic - Next topic

Theme

GUIButtonLocation.Text = "talk to ".Append(locationname);
give me a error
why i cant do it?  ???

o/

Etcher Squared Games

It's in the manual, but it can be a bit confusing.
First of all....

Code: ags

SetText (button)
(Formerly known as SetButtonText, which is now obsolete)

Button.SetText(string newtext)

Changes the text displayed in the specified button to NEWTEXT.
Example: 

btnController.SetText("Enable jibble");

will change button btnController to read 'Enable jibble'.
See Also: Button.GetText, Button.NormalGraphic, Label.SetText


and you'll also want to use
Code: ags
StrCat
StrCat (string str1, string str2)

Appends STR2 to the end of STR1. 
Example: 

string name;
StrCopy(name,"My name is ");
StrCat (name,"Chris"); 

will result a string name which will be "My name is Chris".



so for your problem you'd do

Code: ags

string text;
StrCat(text, "talk to ");
StrCat(text, locationname);
GUIButtonLocation.SetText(text);

website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

Theme

I know, but you used string type, I want to do it with String type
I resolved the problem in another way

but the problem is that
I can do this:

String lookat;
lookat = "look at "
lookat.Append(locationname);

and can't do this:

"look at ".Append(locationname);

o/

monkey0506

That's because anything between quotation marks (") is defined (internally) as a const string, not a String.  You could, however, do:

Code: ags
GUIButtonLocation.Text = String.Format("%s%s", "talk to ", locationname);


Also, Worm III, this is 2.71 code, not 2.7, so it's a wee bit different. ;)

Theme


monkey0506

You're welcome...but I noticed that I did something kind of silly.  You could have just put:

Code: ags
GUIButtonLocation.Text = String.Format("talk to %s", locationname);


Instead of doing the "%s%s" thing...not much of a difference...but it's a bit simpler that way.  It will still do the same thing.

SMF spam blocked by CleanTalk