Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (MadJack, AndrewAMD, Quad), 540 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Question about IF #456458
11/23/15 19:31
11/23/15 19:31
Joined: Nov 2009
Posts: 201
Logitek Offline OP
Member
Logitek  Offline OP
Member

Joined: Nov 2009
Posts: 201
Hello, I have an interesting question about the IF command.

For example:

If (a == 1 && b == 1 && c == 1)
{Do something}

Does the engine now proof each var, also if a is not 1?
I mean: Does the engine break the line and is looking for the next command or does it also check b and c? Also if we already know that a is not 1 and it can not be end in true anymore?

It is interesting for scripts with a lot of IF commands.
I think it is breaking the line, right?







Last edited by Logitek; 11/23/15 19:32.
Re: Question about IF [Re: Logitek] #456459
11/23/15 19:37
11/23/15 19:37
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
It should not check the following statements after encountering a false one in this situation, but it still does. It's easy to proof:

Code:
ENTITY *ent = NULL;

if(ent && ent->x == 0)



This is valid and every normal C compiler won't try to evaluate the second statement, however in Lite-C, you can enjoy a beautiful crash. It's documented somewhere in the manual.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Question about IF [Re: WretchedSid] #456460
11/23/15 19:52
11/23/15 19:52
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
This has been asked for several times on this forum already, and I think it's been on the infamous "list" for a compiler revamp for a few years now.
It would make a lot of stuff like Sid's example or array access easier and nicer.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Question about IF [Re: Superku] #456461
11/23/15 20:00
11/23/15 20:00

M
Malice
Unregistered
Malice
Unregistered
M



Quote:
If (a == 1 && b == 1 && c == 1)


if(a+b+c == 3)


Lol just thought I write something.
Mal

Re: Question about IF [Re: ] #456462
11/23/15 20:17
11/23/15 20:17
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
That's a different/ not equivalent if statement though, for example for a = 3, b = 0 = c. wink


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Question about IF [Re: ] #456463
11/23/15 20:18
11/23/15 20:18
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
early abortion (if(ent && ent->x == 0) example) is not supported by the Lite-C compiler and it's one of the most annoying limitations of Lite-C...
This means, all statements of the if are always evaluated. If you want it different, you have to go with nested ifs... jippijajey

Re: Question about IF [Re: FBL] #456464
11/23/15 20:50
11/23/15 20:50
Joined: Nov 2009
Posts: 201
Logitek Offline OP
Member
Logitek  Offline OP
Member

Joined: Nov 2009
Posts: 201
Okay, interesting.


if (a==1)
{
If (b==1)
{
If (c==1)
{ do something }
}
}

And this example would abort after line 1 if a is not 1, right?

Re: Question about IF [Re: Logitek] #456473
11/24/15 10:21
11/24/15 10:21
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Yes. I admit that this is a clumsy way, but that's how the compiler works - and to change this to the normal C compiler standard is a major act, unfortunately.

Re: Question about IF [Re: jcl] #456591
11/30/15 11:30
11/30/15 11:30
Joined: Nov 2009
Posts: 201
Logitek Offline OP
Member
Logitek  Offline OP
Member

Joined: Nov 2009
Posts: 201
Hello.

How was it with the old c-script and the interpreter? The same way?

Re: Question about IF [Re: jcl] #456595
11/30/15 13:17
11/30/15 13:17
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Originally Posted By: jcl
Yes. I admit that this is a clumsy way, but that's how the compiler works - and to change this to the normal C compiler standard is a major act, unfortunately.

That's a pity but okay...


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Page 1 of 2 1 2

Moderated by  old_bill, Tobias 

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