Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, VoroneTZ), 1,507 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 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 | chip programmers | 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