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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 01:53 AM.


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