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.

DarkBASIC Professional Discussion / Using two "and" in an IF THEN ELSE statement (Help Required)

Author
Message
Mr Bigglesworth
18
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 12th Dec 2010 19:13
So I am making a shooting function



It checks to see if you are aimed down the sights, and plays the approritate fire animation for it. But the problem comes in when it needs to check for both the stimer to be less than the timer and if the varible AimedDown equals 0 or 1.

I don't know how to do this because putting two "and" doesn't work. Any help appricated.
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 12th Dec 2010 19:37
I don't remember how IF statements are processed in DBPro but from the looks of that code it's only executing the first instruction (the stimer assignment). If you want to do multiple instructions use a block instead.
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 12th Dec 2010 19:40
Hi. I've tried using the one line version of if and you can use multiple ands as usual. When you say it doesn't work, do you get an error message?

Have you tried the multi-line version of if to see if it works in that context?

I don't know if this is anything but your variable is called stimer. Is the s at the start a hungarian prefix for string because if it is, you're going to have trouble comparing it to the numeric data type returned by timer() but in this case, you would have got an error message.

I got this code to run as a test. Does it work for you?

Mr Bigglesworth
18
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 12th Dec 2010 20:33
Thanks Lucas Tiridath, I got it to work using your code to structue it.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Dec 2010 20:36 Edited at: 12th Dec 2010 20:38
Quote: "I don't know how to do this because putting two "and" doesn't work. Any help appricated"


What exactly does't work. Your if tests work fine for me. Here's the complete runnable code I used:



Keep left-clicking the mouse to see the output.

I suspect your problem is somewhere else.

Edit Actually, Lucas Tiridath's version is better - but again there's nothing wrong with two or more "and"s.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Dec 2010 21:16
No-one considered rewriting those lines?


In fact, I'd rewrite that first line too to take advantage of some short-cut evaluation:


In the first piece of code, DBPro will check the timer, even if the mouse button isn't pressed, which is a waste of resource.
In the second piece of code, the timer is only checked if the mouse button check succeeds.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Dec 2010 21:32
Quote: "No-one considered rewriting those lines?"


Yes - but I chose to stick to the question.

Login to post a reply

Server time is: 2026-07-21 04:20:43
Your offset time is: 2026-07-21 04:20:43