Page MenuHomeFeedback Tracker

string.ToAscii does not work as documented
Closed, ResolvedPublic

Description

There is a function in scripts\1_core\proto\enstring.c that claims to return the ASCII value of the first character in a string:

	/**
	\brief Converts string's first character to ASCII code
		\param str String for convert to ASCII code
		\return \p ascii code \p int.
		@code
			int ascii = "M".ToAcsii();
			Print(ascii);

			>> ascii = 77
		@endcode
	*/
	proto int ToAscii(string str);

There is a typo in the documentation: "ToAcsii" should be "ToAscii". I corrected this typo before running the example:

void ToAsciiTest()
{
    int ascii = "M".ToAscii();
    Print(ascii);
}

However, even after correcting the typo, running the example code still reports an error, "Not enough parameters in function 'ToAscii'":

Since the ToAscii method requires an argument, I tried changing the code to:

void ToAsciiTest()
{
    int ascii = "M".ToAscii("N");
    Print(ascii);
}

However, the resulting output does not include the ASCII value of "M" (77) or "N" (78). Instead, it seems that the ToAscii method always returns 0:

SCRIPT       : int ascii =   0

Is there a correct way to use the string.ToAscii method so that it actually returns the ASCII value of the first character of the string?

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce

See description

Additional Information

N/A

Event Timeline

tjensen created this task.Aug 2 2021, 2:46 AM
komer added a subscriber: komer.Aug 2 2021, 6:43 AM

Use "c".Hash() where "c" is any input string of length 1

Geez changed the task status from New to Assigned.Aug 2 2021, 4:44 PM

Thanks @Jacob_Mango for the helpful tip!

Geez closed this task as Resolved.Jan 11 2023, 10:33 AM
Geez claimed this task.
Geez added a subscriber: Geez.

Resolved with 1.20 update.