Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,435 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
This should have given an error, but why..? #245549
01/10/09 16:40
01/10/09 16:40
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
So I was happily coding away and all of a sudden I got this strange bug in my code. Took quite some time to find it. Primarily because it wasn't where I expected it to be.

Code:
var interface_cardnum_to_xy(char par_card_num,char x_or_y){
	var par_x;
	var par_y;
	
	switch(par_card_num){
		case 0:	par_x = 0; par_y = 0;	break;
		
		case 1:  par_x = 10; par_y = 10;   break;
		case 2:  par_x = 20; par_y = 10;   break;
                //lotsa more cases here
        }
	if(x_or_y = 0) return(par_x);
	if(x_or_y = 1) return(par_y);
}



what the code does is basically return me the x or y coordinates (depending on the second parameter) for the card id number (the first card id number).

Now heres the deal. The error is quite obviously to be found in the last two lines where it should be if(x_or_y == 0) rather than just '='. But why isn't this output as a syntax error? Am I overlooking something fundamental here?


- Mr Wurm

Re: This should have given an error, but why..? [Re: Mr Wurm] #246008
01/13/09 00:18
01/13/09 00:18
Joined: Jul 2002
Posts: 446
Switzerland
Mr Wurm Offline OP
Senior Member
Mr Wurm  Offline OP
Senior Member

Joined: Jul 2002
Posts: 446
Switzerland
...a small, barely audible and yet slightly shifty *bump* comes along and steals a minuscule split second of your time...


- Mr Wurm

Re: This should have given an error, but why..? [Re: Mr Wurm] #246011
01/13/09 01:15
01/13/09 01:15
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
It's not a syntax error because it's valid syntax.

if(x == 5) is the comparison x with 5.
if(x = 5) is a comparison with x set to 5, thus true.
if(x = 0) is a comparison with x, but set to 0, thus not true.


Click and join the 3dgs irc community!
Room: #3dgs

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1