Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

View Poll Results: Should a<b,a<=b,a>b,a>=b,min(a,b),max(a,b) always compare numbers?
Yes 18 94.74%
No 1 5.26%
Voters: 19. You may not vote on this poll

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-24-2005, 07:11 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #2  
Old 07-24-2005, 07:33 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
Perhaps reimplementing $=? (Torque string comparison operator)
Reply With Quote
  #3  
Old 07-24-2005, 07:35 AM
ZeroTrack ZeroTrack is offline
G2K1 Developer
ZeroTrack's Avatar
Join Date: Apr 2004
Location: LongIsland, NY
Posts: 402
ZeroTrack is on a distinguished road
Send a message via AIM to ZeroTrack
i agree with rick
__________________

Reply With Quote
  #4  
Old 07-24-2005, 07:37 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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.
Reply With Quote
  #5  
Old 07-24-2005, 07:41 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
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?
Reply With Quote
  #6  
Old 07-24-2005, 07:50 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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")
Reply With Quote
  #7  
Old 07-24-2005, 07:51 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
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*
Reply With Quote
  #8  
Old 07-24-2005, 07:51 AM
CheeToS2 CheeToS2 is offline
That Guy
CheeToS2's Avatar
Join Date: Dec 2001
Location: Seattle, WA
Posts: 2,528
CheeToS2 will become famous soon enough
Send a message via AIM to CheeToS2
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.
Reply With Quote
  #9  
Old 07-24-2005, 08:14 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
the first option definitely makes the most sense

who would expect string comparison here?
__________________

Reply With Quote
  #10  
Old 07-24-2005, 11:59 PM
Polo Polo is offline
Classic Systems Admin
Join Date: Sep 2002
Location: Vancouver, Canada
Posts: 735
Polo is on a distinguished road
Send a message via AIM to Polo
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... :/
__________________
Be good little players, or Master Storm will ban you!



Proof that the staff are crazy..
*Ghost Pirate: I'm a little teacup short and stubbe here is my raygun here is my butt
DragonX: Jumping jack rabbits Batman! Our eggo waffles have been stolen! To the batmobile Robin!
X-Mann (RC): I have a head ache
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:53 PM.


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