Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Need your opinion for a technical question (https://forums.graalonline.com/forums/showthread.php?t=60136)

Admins 07-24-2005 07:11 AM

Need your opinion for a technical question
 
In the new scripting engine there is a problem right now: operations that check if a variable is greater or less than another variable work for both numbers and strings, but have different results depending on the type of the variable:
"Atlantis"<"Zoo", 5>3, but also "123"<"4", 123>4,
because strings are alphabetically sorted, numbers by numeric value. Currently you need to at least convert one of the two variables too numeric type (using the int() or float() function) to enforce comparison by numeric value.

Question is: should those operators (<,<=,>,>=) and functions (min,max) always use numeric values for comparison and we add a new function strcmp or similar for comparing strings,
or we keep it like it is but need to enforice numeric comparison by using int() or float().
I would prefer the first option, always do numeric comparison, because string comparison is not needed very often, but often variables are transferred as string (e.g. when sent by client) and if you then accidently compare two client vars or similar and don't use int() or float() then you get bad values and don't directly know why.
For the equality operators (==,!=) we can keep compatibility with all variable types since numeric variables are the same no matter if you compare their numeric value or their string representation.

Rick 07-24-2005 07:33 AM

Perhaps reimplementing $=? (Torque string comparison operator)

ZeroTrack 07-24-2005 07:35 AM

i agree with rick

Admins 07-24-2005 07:37 AM

Quote:

Originally Posted by Rick
Perhaps reimplementing $=? (Torque string comparison operator)

Like I said it's not required for equality operators since it is the same anyway if you do 123==123 or if you do "123"=="123". Graal script has variant variables so it's not required to have 4 different equality operators (for string, number, object, links). This is about greater/less operators.

Rick 07-24-2005 07:41 AM

Quote:

Originally Posted by Stefan
Like I said it's not required for equality operators since it is the same anyway if you do 123==123 or if you do "123"=="123". Graal script has variant variables so it's not required to have 4 different equality operators (for string, number, object, links). This is about greater/less operators.

[edit]Okay, it seems I misread this thread. Nevermind.[/edit]

[edit2]string.compare(otherstring) ?[/edit2]

Also:

If this is implemented. Will you raise a runtime script error if an attempt to compare a string that can't be converted to a number?

Admins 07-24-2005 07:50 AM

It would just be zero then, don't think it would be a problem, 1 > "hello" since "hello" would be converted to 0 (its already doing that now since 1 is a number). Also "orange" > "apple" would be false since both would be converted to 0 (currently it would say "true" because alphabetically "apple comes before "orange")

Rick 07-24-2005 07:51 AM

Quote:

Originally Posted by Stefan
It would just be zero then, don't think it would be a problem, 1 > "hello" since "hello" would be converted to 0 (its already doing that now since 1 is a number)

Yeah, but I don't think that behavior is good. *shrug*

CheeToS2 07-24-2005 07:51 AM

Quote:

Originally Posted by Stefan
Question is: should those operators (<,<=,>,>=) and functions (min,max) always use numeric values for comparison and we add a new function strcmp or similar for comparing strings,
or we keep it like it is but need to enforice numeric comparison by using int() or float().

Given the details, I'd prefer the first option as well. Like you said, string comparisons are rarely used, and if the client sends everything serverside as a string, people would need to use int()/float() too much if it were done the other way. It will be much simpler in the long run if the first option is used.

Evil_Trunks 07-24-2005 08:14 PM

the first option definitely makes the most sense

who would expect string comparison here?

Polo 07-24-2005 11:59 PM

why not use <=, >=, < and > for numerical comparison, then have somthing like le, ge, lt and gt for lexographical comparison? (Like in Perl ^^). Or maybe just some string comparing functions... :/


All times are GMT +2. The time now is 11:37 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.