Adventure Game Studio

AGS Development => Engine Development => Topic started by: Monsieur OUXX on Sun 01/11/2020 21:17:43

Title: String.Contains ? What are you doing here little buddy?
Post by: Monsieur OUXX on Sun 01/11/2020 21:17:43
Try this in 3.5.0.24

Quotevoid game_start()
{
    String s = "a";
    if (s.Contains(" ")) {
         AbortGame("Wut?");
    }
}


Strings are not even supposed to have a function "Contains".

I've tried to overload the function with my own extender, but the compiler says :
QuoteString.Contains already exists
Title: Re: String.Contains ? What are you doing here little buddy?
Post by: Crimson Wizard on Sun 01/11/2020 22:31:52
I confirm, this function is declared in String and exists in the engine at least since AGS 3.2.1.

Quote
import int     Contains(const string needle);   // $AUTOCOMPLETEIGNORE$

but it's marked with AUTOCOMPLETEIGNORE so does not show up in autocomplete.

Also, judging by the above test result, it's not working correctly. Maybe it was introduced by CJ at some point, but never finished, and forgotten.

EDIT: actually, it's not bool, it returns -1 if it fails, and >=0 for the index of the found substring.

Also, it's case-insensitive.
Title: Re: String.Contains ? What are you doing here little buddy?
Post by: Snarky on Sun 01/11/2020 23:33:57
According to the manual it's an old (deprecated) function, superseded by String.IndexOf(). Sounds like it actually functions identically to IndexOfâ€"maybe it was just renamed to better describe its functioning.
Title: Re: String.Contains ? What are you doing here little buddy?
Post by: Crimson Wizard on Sun 01/11/2020 23:42:25
Quote from: Snarky on Sun 01/11/2020 23:33:57
According to the manual it's an old (deprecated) function, superseded by String.IndexOf(). Sounds like it actually functions identically to IndexOfâ€"maybe it was just renamed to better describe its functioning.

Yes, that would explain. And IndexOf function is an alias to same implementation in the engine.

From Changes.txt:
Quote
VERSION 3.1, October 2008
<...>
- Renamed String.Contains to String.IndexOf to reduce confusion with other
   languages such as Java and C#. String.Contains will continue to work as well for
   the foreseeable future
Title: Re: String.Contains ? What are you doing here little buddy?
Post by: Monsieur OUXX on Mon 02/11/2020 17:20:37
In regards to all of the above, either this function is meant to have a life of its own and be changed to returning a bool, or it's exactly redundant to IndexOf and it should be deleted entirely.
Title: Re: String.Contains ? What are you doing here little buddy?
Post by: Crimson Wizard on Mon 02/11/2020 18:21:29
In the backward-compatible version of the engine it may be hidden behind the script api check, as we do to deprecated functions now, as in theory it could've been used in early 3.* games.
It may be easily deleted in versions that allow breaking changes.
Title: Re: String.Contains ? What are you doing here little buddy?
Post by: Monsieur OUXX on Tue 03/11/2020 15:28:10
OK! Good enough for me. I didn't mean to be pedantic. Thanks for answering!