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 (Hanky27, AndrewAMD), 1,271 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Simple comparision question #424539
06/18/13 16:52
06/18/13 16:52

M
Malice
Unregistered
Malice
Unregistered
M



The manual says you should not do a Boolean check on a pointer and comp it's member(s) values in the same if(). Is this still true. Example below.

Code:
if ( pan_temp && pan_temp.pos_x != 1024 ) // The manual says don't do this.

if ( pan_temp )  // Manual say do this.
{
   if ( pan_temp.pos_x != 1024 );
}



Also does this apply if you are doing the Boolean check on the contents of a VAR and not it's pointer.

Code:
var I = 999;

if ( I && I > 500 )


Re: Simple comparision question [Re: ] #424542
06/18/13 17:15
06/18/13 17:15
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Why do you need to check 'var' for? If it's not declared, it won't compile anyway, or am I getting your point wrong?

Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Simple comparision question [Re: 3run] #424546
06/18/13 17:25
06/18/13 17:25
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Quote:

The manual says you should not do a Boolean check on a pointer and comp it's member(s) values in the same if(). Is this still true. Example below.


Still true. Maybe in near future it will be changed.


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: Simple comparision question [Re: rayp] #424548
06/18/13 17:32
06/18/13 17:32

M
Malice
Unregistered
Malice
Unregistered
M



@3Run I am checking if the vars content is != 0. Content not pointer. I am trying to see if it has a value not if it was declared.

Code:
if ( I ) is same as if(I != 0)



But I might to totally wrong in my understand of what I did above.


@rayp Thank you for this reply. That's is where my code is breaking.

Last edited by Malice; 06/18/13 17:34.
Re: Simple comparision question [Re: ] #424549
06/18/13 17:34
06/18/13 17:34
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Code:
if (!i) _empty();
if (i) _notempty();

Do u mean this ?

edit: So if (i) should be the same as if (i!=0) yes.

Last edited by rayp; 06/18/13 17:35.

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: Simple comparision question [Re: rayp] #424551
06/18/13 17:36
06/18/13 17:36

M
Malice
Unregistered
Malice
Unregistered
M



@rayp Yes that is what I'm asking. Does the same rule apply as pointers here

Code:
if( i && i != 500) // Bad ?

if(i)   // Good?
{ 
   if(i != 500)
}



I have to stop using i because of autocaps for i

Last edited by Malice; 06/18/13 17:38.
Re: Simple comparision question [Re: ] #424554
06/18/13 17:43
06/18/13 17:43
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
no you dont need to check VAR's before.

edit:
Code:
var test = 1;
if (test > 0 && test < 2) _test_is_one();
if (!test) _test_is_notone();

ENTITY* test2;
if (test2) if (test2.x == 10) ...


Last edited by rayp; 06/18/13 17:45.

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: Simple comparision question [Re: ] #424556
06/18/13 17:48
06/18/13 17:48
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
The manual says that this is "good" because the program checks the whole comparision before deciding if it is true or false.

Code:
ENTITY * ent;

void main()
{
	if(ent && ent.x > 5)
		ent.x = 0;
}



this will result in an error.

ent doesn't exist so if you check if(ent) it is true.
but in the comparison above the program doesn't abort it but checks the next comparison (ent.x > 5)
but ent doesn't exist and this causes an error.

edit: note that this only applies for pointers.

Last edited by Kartoffel; 06/18/13 17:51.

POTATO-MAN saves the day! - Random
Re: Simple comparision question [Re: ] #424557
06/18/13 17:49
06/18/13 17:49
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Why don't you use something like this:
Code:
var checkVar(var CHECK){
	if(CHECK != 0){ return(1); }
	if(CHECK == 0){ return(0); }
}

Hope, it helps grin

Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Simple comparision question [Re: ] #424559
06/18/13 17:56
06/18/13 17:56
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
EDIT: sorry, only read your first post when i wrote it ^^
Quote:
The manual says you should not do a Boolean check on a pointer and comp it's member(s) values in the same if(). Is this still true.


Yes.

Quote:
Also does this apply if you are doing the Boolean check on the contents of a VAR and not it's pointer.


It depends of what you want to do. variables in if's evaluate to "false" if they are 0 and to "true" if they are non-zero. Here are some examples:
Code:
i=10;
if(i) -> if(true) -> will execute
i = -20;
if(i) -> if(true) -> will execute
i = 0;
if(i) -> if(false) -> will not execute



so your second example will work only if I > 500 ("I &&" is useless, because if(i) means if i is not 0. But your second contion I>500 includes that i is not null).

Why do you need to check it with poitners in an if?
3dgs evaluates all conditions in the if. If you have something like the following:
Code:
pan_temp = NULL;
if( pan_temp && pan_temp.pos_x != 1024 )


It will evaluate to the following:
Code:
if(NULL && NULL.pos_x != 1024 )


And because NULL has no property pos_x, the compiler will show an error.

Last edited by krial057; 06/18/13 17:56.
Page 1 of 2 1 2

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