[4.1.0] Orange ZScript console warnings

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
User avatar
Kostov
 
 
Posts: 2020
Joined: Thu Dec 26, 2013 3:26 pm
Location: Sweden
Contact:

[4.1.0] Orange ZScript console warnings

Post by Kostov »

These warnings show up in the console when launching GZDoom 4.1.0. I have no idea if it’s likely to affect gameplay, and it’s probably not a bug per se, but it’s definitely not a nice sight.

Code: Select all

Script warning, "gzdoom.pk3:zscript/ui/statscreen/statscreen.zs" line 24:
Call to deprecated function CharAt
Script warning, "gzdoom.pk3:zscript/ui/statscreen/statscreen.zs" line 24:
Accessing deprecated function CharAt - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 64:
Call to deprecated function ToLower
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 64:
Accessing deprecated function ToLower - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 65:
Call to deprecated function ToLower
Script warning, "gzdoom.pk3:zscript/ui/menu/search/query.zs" line 65:
Accessing deprecated function ToLower - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 202:
Call to deprecated function CharAt
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 202:
Accessing deprecated function CharAt - deprecated since 4.1.0
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 235:
Call to deprecated function CharAt
Script warning, "gzdoom.pk3:zscript/ui/menu/conversationmenu.zs" line 235:
Accessing deprecated function CharAt - deprecated since 4.1.0
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: [4.1.0] Orange ZScript console warnings

Post by Rachael »

Yikes. This will warrant a 4.1.1 point release.
User avatar
DoomKrakken
Posts: 3482
Joined: Sun Oct 19, 2014 6:45 pm
Location: Plahnit Urff
Contact:

Re: [4.1.0] Orange ZScript console warnings

Post by DoomKrakken »

Oh yeah, that happened with my mod too...
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: [4.1.0] Orange ZScript console warnings

Post by Matt »

What do we use in place of CharAt and ToLower?

EDIT: I just noticed that no warnings appear for HD's use of the ToLower() function. Is this different?
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [4.1.0] Orange ZScript console warnings

Post by _mental_ »

Matt wrote:What do we use in place of CharAt and ToLower?
ByteAt() and MakeLower().
Matt wrote:I just noticed that no warnings appear for HD's use of the ToLower() function. Is this different?
This depends on ZScript version required for your mod.
User avatar
Lagi
Posts: 676
Joined: Sat Jun 23, 2018 12:51 pm
Location: Thou shalt alter thy beliefs with new evidence

Re: [4.1.0] Orange ZScript console warnings

Post by Lagi »

how to replace CharAt with BytaAt?

CharAt is a string function, while BytaAt is a int.
int ByteAt (int pos) const

(Need more info)

String CharAt (int pos) const (deprecated)

(Note: this has been deprecated in favor of ByteAt, CodePointCount and GetNextCodePoint.)
Returns the character at the specified position as string.

String s = "abcd";
String chrat = s.CharAt(1); // should be "b"
dont work as expected string
Spoiler:
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.1.0] Orange ZScript console warnings

Post by Graf Zahl »

At the moment you'll have to convert the character back to a string with String.Format("%c", ...), but the main reason these were deprecated is that with Unicode strings such algorithms that pick apart the string character by character won't work as expected and are generally discouraged.
User avatar
Lagi
Posts: 676
Joined: Sat Jun 23, 2018 12:51 pm
Location: Thou shalt alter thy beliefs with new evidence

Re: [4.1.0] Orange ZScript console warnings

Post by Lagi »

sorry I think its simple, but im defeated by syntax

i have this (it works, just want to remove errors from startup log)
lumpString.CharAt(currentPos)
charAt is now excommunicado, and ByteAt is halal.

so i come up with this :roll:
lumpString.Format("%c", ByteAt(currentPos) )
Spoiler: my logic
and my school teacher said : How can you be so stupid:
Script error, "Bitter Heretic.pk3:zscript/pyw/parse.zsc" line 139:
Call to unknown function 'ByteAt'
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.1.0] Orange ZScript console warnings

Post by Graf Zahl »

Aside from the fact that you just ignored the entire motivation not to access bytes, this doesn't work because you need to specify the string you want to read from.
But your code still isn't Unicode safe and will only work if your text is guaranteed to be ASCII only.

These deprecations were made to clearly show that CharAt is not a safe function in a Unicode environment.
User avatar
3saster
Posts: 199
Joined: Fri May 11, 2018 2:39 pm
Location: Canada

Re: [4.1.0] Orange ZScript console warnings

Post by 3saster »

Lagi wrote:Big mess
If you need help, you might want to speak like a normal person...

That being said, the "safe" way, if the deprecation messages are anything to go by, instead of

Code: Select all

lumpString.CharAt(currentPos)
do

Code: Select all

lumpString.Mid(currentPos,1)
You might want to use a devbuild for development purposes, if only for the fact that the latest devbuilds feature deprecation messages that actually say what you should use instead. In this case, Left and Mid are recommended instead of CharAt.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.1.0] Orange ZScript console warnings

Post by Graf Zahl »

Left and Mid are not a single bit safer than CharAt, they are just another way to ignore Unicode and create broken code that will fail if subjected to non-English text. The proper way to process a string character by character is to iterate over it with GetNextCodePoint, but that seems to be a *bit* too inconvenient for some people...
SanyaWaffles
Posts: 800
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: [4.1.0] Orange ZScript console warnings

Post by SanyaWaffles »

I've figured out how to properly do ByteAt based on what you said above.

Code: Select all

String unichar = String.Format("%c", str.ByteAt(currentPos));
seems to be how it's done, with str being whatever string you want to work on.

All the Wiki says about GetNextCodePoint is "(Need more info)". It seems to return two ints. Looking at the source code, it returns the codepoint and the current position.

I tried writing some functions for these:

Code: Select all

	String UniCharAt(String str, int pos)
	{
		String ret = String.Format("%c", str.ByteAt(pos));
		
		Console.PrintF(ret);
		
		return ret;
	}
	
	String UniLeft(String str, int len)
	{
		String find;
		
		for (int i = 0; i < len; i++)
		{
			find.AppendCharacter(str.GetNextCodePoint(i));
		}
		
		Console.PrintF(find);
		
		return find;
	}
	
	String UniMid(String str, int pos, int len)
	{
		String find;
		int max = pos + len;
		
		for (int i = pos; i < max; i++)
		{
			find.AppendCharacter(str.GetNextCodePoint(i));
		}
		
		Console.PrintF(find);
		
		return find;
	}
I tested it and it seems to work fine, but I'm sure there's some missing checks. I'm still working on the code, but this is a good starting point I think for anyone wanting to explore this.
Last edited by SanyaWaffles on Sat May 30, 2020 2:17 am, edited 1 time in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.1.0] Orange ZScript console warnings

Post by Graf Zahl »

No, that's not correct. Virtually everything posted here ignores that UTF-8 is a variable length encoding and for proper processing the code needs to deal with this fact.
This all will break as soon as you try to print the text character by character.

Especially GetNextCodePoint's second return value is important, it is the incremented index so that it points to the start of the next code point, not the next byte.
SanyaWaffles
Posts: 800
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: [4.1.0] Orange ZScript console warnings

Post by SanyaWaffles »

Then how do you use GetNextCodePoint and it's related functions reliably to account for this? I've been looking at this for over an hour now and I cannot wrap my head around it and I'm not finding many examples. The only thing I've seen mentioned is in this thread and it gives no examples of how the functions are used.
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: [4.1.0] Orange ZScript console warnings

Post by m8f »

I have an example here. This function compares two unicode strings character by character, and composes a colored string where matching characters are green, and not matching characters are red.
Post Reply

Return to “Closed Bugs [GZDoom]”