Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-22-2006, 11:26 AM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Assignment in IF Clause

PHP Code:
if ( temp.rid true )
  {
  
// Stuff
  

Does NOT work.

PHP Code:
temp.rid true;
if ( 
temp.rid )
  {
  
// Stuff
  

DOES.

Wrapping assignment in brackets doesn't fix this problem.


Practical Usage:

PHP Code:
function onCreated()
  {
  while ( 
temp.item this.(@ "items"temp.count++ ) )
    {
    
// Stuff
    
}
  } 
Reply With Quote
  #2  
Old 06-22-2006, 12:00 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by JustBreathe
Does NOT work.
I believe this is for compatibility to GS1 where it was a feature for compatibility with Delphi-style comparisions.
Reply With Quote
  #3  
Old 06-22-2006, 12:11 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
It doesn't set anything at all. It totally ignores the assignment. I thought it was to prevent those who do if ( player.chat = "command" ) stuff;, but... Just because they have no notion of what an assignment operator does, doesn't mean that we should follow suit and make it into a comparison operator when those who do know have, now, no way of using the assignment operator.
Reply With Quote
  #4  
Old 06-22-2006, 12:13 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by JustBreathe
It doesn't set anything at all. It totally ignores the assignment. I thought it was to prevent those who do if ( player.chat = "command" ) stuff;, but... Just because they have no notion of what an assignment operator does, doesn't mean that we should follow suit and make it into a comparison operator when those who do know have, now, no way of using the assignment operator.
What exactly are you expecting an assignment to return?
__________________
Skyld
Reply With Quote
  #5  
Old 06-22-2006, 12:15 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
GS2 automatically translates if (blah = thing) to if (blah == thing) to fix stupid people.
Reply With Quote
  #6  
Old 06-22-2006, 12:18 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by Skyld
What exactly are you expecting an assignment to return?
temp.var = temp.var2 = temp.var3 = true;

is the same as

temp.var = ( temp.var2 = ( temp.var3 = true ) );
temp.var = ( temp.var2 = true );
temp.var = ( true );

if ( temp.var )... Temp.var would return true.
Reply With Quote
  #7  
Old 06-22-2006, 12:19 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by JustBreathe
temp.var = temp.var2 = temp.var3 = true;

is the same as

temp.var = ( temp.var2 = ( temp.var3 = true ) );
temp.var = ( temp.var2 = true );
temp.var = ( true );

if ( temp.var )... Temp.var would return true.
So if you want it to return the value of the variable that you are assigning to, why did you not just say so?
__________________
Skyld
Reply With Quote
  #8  
Old 06-22-2006, 12:22 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Quote:
Originally Posted by Skyld
So if you want it to return the value of the variable that you are assigning to, why did you not just say so?
If you used it in other languages, as does the person I was addressing the problem to has probably done, you would have understood.
Reply With Quote
  #9  
Old 06-22-2006, 02:14 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
There are tons of scripts that the use wrong assignment operator, that's why it's better to keep this. It's not easy to debug either. Eventually it could display a warning when compiling the script and detecting an assignment operator inside an if/while/do statement. I would recommend to put the assignment into a separate line, that is better for readability anyway.
Reply With Quote
  #10  
Old 06-22-2006, 02:18 PM
JustBreathe JustBreathe is offline
Registered User
Join Date: Jun 2006
Posts: 59
JustBreathe is on a distinguished road
Could you have a server option that prevents GS1 backward compatibility.

I think leaving it as such is just encouraging bad standardization. Such as IE's CSS: The bad standardization impairs improvement of their CSS.
Reply With Quote
  #11  
Old 06-22-2006, 02:37 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
Could be a server option yes
Reply With Quote
  #12  
Old 06-22-2006, 02:50 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
I would love for that to be a server option.
Reply With Quote
  #13  
Old 06-22-2006, 02:51 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
Quote:
Originally Posted by Twinny
I would love for that to be a server option.
I'm suprised Stefan is going with that now

I'd also be happy to see this, even though I'm not much into dev anymore.
Reply With Quote
  #14  
Old 06-22-2006, 07:34 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
Quote:
Originally Posted by Skyld
So if you want it to return the value of the variable that you are assigning to, why did you not just say so?
It has practical applications mainly with functions that return false on error. Instead of having to have two separate lines you can do it all in one.

ie:
PHP Code:
// ..
if(!(temp.blah Foo(this.bar))) {
  echo(
"ZOMG ERROR");
}
// ..
function Foo(bar) {
  if(
bar 10) return false;
  else return 
bar 10;

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:57 AM.


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