Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: AnInhumer on Wed 08/06/2005 20:27:18

Title: StrGetCharAt
Post by: AnInhumer on Wed 08/06/2005 20:27:18
How can you convert the char returned by the StrGetCharAt into a string so that it can be used in the standard functions.
Title: Re: StrGetCharAt
Post by: strazer on Wed 08/06/2005 21:08:15
StrFormat(thestring, "%c", thechar);
Title: Re: StrGetCharAt
Post by: AnInhumer on Wed 08/06/2005 21:13:27
Thank you, I hadn't thought of that.

I can understand the use of char but why not a string?
All the functions use int or string meaning the fact it returns something is useless

Someone is now going to point out why it isn't
Title: Re: StrGetCharAt
Post by: Denzil Quixode on Thu 09/06/2005 00:48:37
Chars can be useful in certain circumstances since you can use ranges to find if a particular character is an upper case letter, a lower case letter, a number, etc. as opposed to StrComping a string to every single value.

It might be useful to have a substring-extracting function aswell, though.
Title: Re: StrGetCharAt
Post by: Gilbert on Thu 09/06/2005 02:46:50
Quote from: AnInhumer on Wed 08/06/2005 21:13:27
I can understand the use of char but why not a string?
All the functions use int or string meaning the fact it returns something is useless

Because AGS cannot return a string in a function, nor can strings be used directly in arithmetic expressions.
For example you cannot do stuff like:
string blah = "HAHAHA";
or
function MakeString(int num){
  string blargh;
  //blahblablabla
  return blargh;
}

You need to use the Str*() functions for string operations.
Title: Re: StrGetCharAt
Post by: strazer on Thu 09/06/2005 02:52:59
QuoteIt might be useful to have a substring-extracting function aswell, though.

You mean something like that?:


function StrCopyEx(string destination, string source, int start, int length) {
  StrCopy(destination, "");
  int end = start + length;
  while (start < end) {
    char letter = StrGetCharAt(source, start);
    StrFormat(destination, "%s%c", destination, letter);
    start++;
  }
}
Title: Re: StrGetCharAt
Post by: monkey0506 on Thu 09/06/2005 06:24:51
That would be a good one to add to the StringAdditions SM.  I found a problem with one of the functions in there anyway and just haven't updated it since fixing it.  I'll work on that tomorrow.  Erm... Later, today? :o ('Tis past midnight already?)