Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Bug Reports / 1 line 2 if/then statements

Author
Message
Mychal B
13
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 6th Jul 2011 14:24
Not sure whether or not this would be considered a bug but I thought I'd post it just in case

I was testing two statements on one line as so...

if x = 1 then y = 1 : if x = 2 then y =2

Only the first statement is checked, whether or not it is true. The second statement doesn't get touched from what I could see.

I simply split them up on two lines and it worked fine.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Jul 2011 14:44 Edited at: 6th Jul 2011 14:46
Quote: "Only the first statement is checked, whether or not it is true."


How did you test that claim?

If x is 1 then the rest of the line is executed - but since x is not 2 in that case then the second condition is false so y will not be set to 2.

If, on the other hand, x is 2 then the rest of the line after the first test is skipped. That is the purpose of the If/then construct in DBPro. The following snippet shows that your statement is wrong - the second test IS checked when the first test passes:



This is what the Help file says on the subject of the IF command:

Quote: "If the condition is true, the commands after the THEN keyword are performed. Ensure that your commands after the THEN keyword are separated by a colon(). If the condition is false, the rest of the line is skipped."


That is fairly clear in my opinion (leaving aside the small matter of the omission of the else/endif option ).
Mychal B
13
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 6th Jul 2011 14:49
So if the statement is false the 2nd command wont be executed even though you have a colon?

I came across it when switching sprites depending on whether or not the player wanted to invert the controls. I just thought that the second statement would still execute if the previous was followed by a colon, even if the first statement was false
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Jul 2011 14:59
Quote: "So if the statement is false the 2nd command wont be executed even though you have a colon?"


Yes. I agree that should be made clear in the Help file.

Login to post a reply

Server time is: 2024-04-19 20:44:09
Your offset time is: 2024-04-19 20:44:09