Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: mrsix on Thu 16/10/2008 08:23:26

Title: Having problems adding extra data on a label, without clearing original text
Post by: mrsix on Thu 16/10/2008 08:23:26
Sorry if i'm being a bit silly!
But i'm having a problem with a label.

I have some buttons, when I press button 1, I want it to add a "1" to the label. When I press it again, I want it to add another "1", so I would get "11"
If i pressed button one 4 times it would say "1111" in the label.

I can make it so that pressing button one sets the label to 1, but thats it. Im guessing that because it is text rather than numericals, I have to stop it from calculating, but rather ADDING the text next to it.
I thought using a code something like

function Button1_OnClick(GUIControl *control, MouseButton button)
{
Label.Text = Label.Text +("1");
}

So that it basically says keep the label as it is, but add a 1 next to what it currently contains. Obviously the above code does not work, but you can see what I mean. Does anybody know how to solve this simple problem, or even if it is possible with a label? Sorry, I have searched all evening yesterday on the manual and could not find an example i'm afraid.
Title: Re: Having problems adding extra data on a label, without clearing original text
Post by: Gilbert on Thu 16/10/2008 08:51:48
Use
Label.Text = Label.Text.Append("1");
instead.
Title: Re: Having problems adding extra data on a label, without clearing original text
Post by: monkey0506 on Thu 16/10/2008 08:52:02
The proper function is String.Append. You could alternately in this case use String.AppendChar using the ASCII character '1' (note the single-quotes for a char, not "1" which is a string).
Title: Re: Having problems adding extra data on a label, without clearing original text
Post by: mrsix on Thu 16/10/2008 09:21:20
Thankyou  both, you've solved the problem  :)