Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ghostlady on Fri 15/06/2007 04:20:50

Title: String command Problem
Post by: Ghostlady on Fri 15/06/2007 04:20:50
What is different with the "string" command in V2.72 from V2.71?  I am trying to put conversation text on a gui, the way I did it using the prior version and I am getting this error:

Type mismatch:  Cannot convert 'const string' to 'string'

Global Script:
function SaySpecial(Character *thechar, string message) {
  slabel.TextColor = thechar.SpeechColor;
  slabel.SetText(message);
  thechar.SayAt(0, 0, 0, message); // say text but hidden (width 0), so voice speech plays
  slabel.SetText("");

Script Header:
import function SaySpecial(Character *thechar, string message); //make function useable in room scripts as well

Room Script:
// script for Room: Player enters room (after fadein)
    gGui4.Visible = true;
    SaySpecial(cSarah, "Here at last.");
    gGui4.Visible = false; }   
}
Title: Re: String command Problem
Post by: Gilbert on Fri 15/06/2007 04:35:03
Try to capitalise the S in string.

function SaySpecial(Character *thechar, String message) {
  slabel.TextColor = thechar.SpeechColor;
  slabel.SetText(message);
  thechar.SayAt(0, 0, 0, message); // say text but hidden (width 0), so voice speech plays
  slabel.SetText("");
Title: Re: String command Problem
Post by: monkey0506 on Fri 15/06/2007 04:41:30
AGS 2.71 and later uses the String type instead of the string type (note capitalization (it matters!)). If you still use the old-style strings in your scripts, simply change "string message" to "const string message" in your functions and voila!

If you plan on upgrading to the new String type I would suggest using a String as the parameter as opposed to a const string. It helps enforce the changes (if you're wanting to make them that is), and you can always pass an old-style string through a String parameter like this:

function SomeFunc(String param) {
  // ...
  }

function OtherFunc() {
  string str;
  StrCopy(str, "This is some text!");
  SomeFunc(String.Format("%s", str));
  }
Title: Re: String command Problem
Post by: Ghostlady on Fri 15/06/2007 05:01:57
Capital S made a big difference.  I'll play around with the new formatting of Strings.  Thanks to the both of you. 
Title: Re: String command Problem
Post by: monkey0506 on Fri 15/06/2007 05:40:26
If you want to upgrade, try making sure "Enforce new-style strings" is checked in your General Settings pane. That should throw up lots of things for you to check into. But basically the new String type works like this:

string str;                             -->   String str;
StrCopy(str, "This is some text!");     -->   str = "This is some text!";
StrCat(str, " And this is some more."); -->   str = str.Append(" And this is some more.");
string otherStr;
StrFormat(otherStr, "%d", some_int);    -->   String otherStr = String.Format("%d", some_int);
StrCopy(otherStr, str);                 -->   otherStr = str;
if (StrComp(str, otherStr) == 0) {      -->   if (str.CompareTo(otherStr) == 0) {
                                        --> // (also:) if (str == otherStr) {
  Display(str);                         -->   Display(str);
  }


Something you should note is that the String type is internally defined as a pointer. If you don't understand pointers that's all-right, the only part you really need to know is that if you type:

String str;

Then the variable str will actually hold the value null. You cannot operate on null Strings! Attempting to do so will crash your game. As long as the variable is not global (you are defining it within a function) you can assign it a default value automatically, i.e.:

// inside some function
String str = "This is some text!";

// outside of all functions
//String g_str = "This is some text!"; // this will produce an error, use:
String g_str; // instead and set the initial value inside a function, such as game_start


For a full list of the new functions, simply look up "String functions" in the manual (for AGS 2.71 or later ;)).

[EDIT:]

This (http://americangirlscouts.org/agswiki/Upgrading_to_new-style_Strings) may be useful...:o...holy hell I have way too much free time.
Title: Re: String command Problem
Post by: Ghostlady on Sat 16/06/2007 00:58:22
Ok, this is good.  I do understand pointers.

I didn't realize there was another manual other than the one that comes with the software.  This is even a bigger help.