Graal Forums  

Go Back   Graal Forums > Development Forums > Tech Support
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-22-2006, 10:43 AM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Inconsistencies ( return values )

It is said that an 'if clause' should return true if the evaluation within isn't false.

PHP Code:
function onCreated()
  {
  
// eval function: return ( var ? true : false );
  // evalFIX function: return ( var != false );

  
eval( new TStaticVar() ); // returns false
  
evalFIX( new TStaticVar() ); // returns true

  
eval( false ); // returns false
  
evalFIXfalse ); // returns false

  
eval( "" ); // returns false
  
evalFIX"" ); // returns false

  
eval( null ); // returns false
  
evalFIXnull ); // returns false

  
eval( "false" ); // returns false
  
evalFIX"false" ); // returns false

  
eval( {"stuff""Things"} ); // returns false
  
evalFIX( {"stuff""Things"} ); // returns true

  
eval( "stuff,Things" ); // returns true
  
evalFIX"stuff,Things" ); // returns true

  
eval( true ); // returns true
  
evalFIXtrue ); // returns true

  
eval( "Stuff" ); // returns true
  
evalFIX"Stuff" ); // returns true

  
}

function eval( var )
  {
  return ( var ? 
true false );
  }

function 
evalFIX( var )
  {
  return (var != 
false);
  } 
As shown:

Objects return false in an if clause... obj != false, returns true.

"string,var" returns true, while {"string","var"} returns false. ( string representation of array, and array )...


I believe it would be better having the evalFix, rather than the eval as return... This would allow flexability as such:

PHP Code:
  if ( pl getPlayer("JustBreathe") )
    {
    
pl.stuff;
    } else {
    return 
false;
    } 
Reply With Quote
  #2  
Old 06-22-2006, 12:12 PM
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
Okay, nevermind, I jumped the gun there by misreading your post... I'll re-edit this post later.



Okay, I've looked at this problem in detail.


evalFIX() works properly, yes.
eval() - the problem may or may not be a problem.


arg ? true : false

arg before it does ?: gets cast to a float -- Objects / arrays get cast to 0.0 obviously, which is why that logic fails with them.

Last edited by Rick; 06-22-2006 at 12:45 PM..
Reply With Quote
  #3  
Old 06-22-2006, 02:14 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by Rick
Okay, nevermind, I jumped the gun there by misreading your post... I'll re-edit this post later.



Okay, I've looked at this problem in detail.


evalFIX() works properly, yes.
eval() - the problem may or may not be a problem.


arg ? true : false

arg before it does ?: gets cast to a float -- Objects / arrays get cast to 0.0 obviously, which is why that logic fails with them.
Mhmm... Replace eval() by...
PHP Code:
if ( var ) return true;
else return 
false
... It does the same as arg ? true: false;

It casts the variable, yes... But that's where the problem is. It should only return false when it is false ("", null, false, "false" ), and in every other occasion, return true ( -1, "foo", {"stuff"}, new Object() ).
Reply With Quote
  #4  
Old 06-22-2006, 02:36 PM
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
I don't know if the behaviour should be changed. The only thing that seems to be different is the check if an object is not null, and return true in that case. You can check that yourself though, with "if (obj==NULL)". For optimization it is currently doing "float(condition)!=false" instead of "condition!=false".
Reply With Quote
  #5  
Old 06-22-2006, 02:37 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Stefan: Seems like your post was deleted.

( talked about converting to float and bool )

Couldn't you work it out with type() ?
PHP Code:
function eval( var )
  {
  switch( var.
type() )
    {
    case 
0:
      return var != 
false;
    case 
1:
      return var != 
"";
    case 
2:
      return var != 
null;
    case 
3:
      return 
true// ... Just saying it has a type array means it exists!
    
}
  } 
Reply With Quote
  #6  
Old 06-22-2006, 02:48 PM
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
I have deleted and created a new post. It is doing such a check when you compare like 'condition!=false', but for optimization it is doing 'float(condition)!=0'
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:43 AM.


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