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.

Newcomers DBPro Corner / IF statement question?

Author
Message
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 18th Mar 2006 18:05
Hi

Ive just recieved my copy of the new "Hands on Darkbasic Vol 1"
I`m only up to activity 1.7 on page 8, and I have a question which I hope you can help me out with.

Quote: "
If

crossbow is too high:
say "Down a bit"
crossbow is too low:
say "Up a bit"
crossbow is too far right:
say "Left a bit"
crossbow is too far left:
say "Right a bit"
crossbow is on target:
say "Fire"

endif

"

Now it states that if you change the format of the IF statment. Several mutually exclusive conditions, can be declared in a single IF statement.

I have tried but failed, can anyone tell me is this possible ?
If it is could you give me an example and an explanation as I'm extremely confused.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Mar 2006 18:43
Quote: "Several mutually exclusive conditions, can be declared in a single IF statement."


The above aren't mutually exclusive. You can be too high and too far right.

If they were mutually exclusive, you would probably use SELECT / CASE statements. If the book hasn't got that far, then take a look and using IF / ELSE / ENDIF.

Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 18th Mar 2006 20:29
Hi batvink

Thanks for your post, I'm only quoting what the book says, it says there are three forms of IF statements:

Quote: "
IF condition THEN
instructions
ENDIF

IF condition THEN
instructions
ELSE
instructions
ENDIF

IF
condition 1:
instructions
condition 2:
instructions
condition x:
instructions
ELSE
instructions
ENDIF
"

It doesn't mention about CASE, END CASE it just says that by placing a colon at the end of each option, only the condition that is true, will be carried out, all others will be ignored.

The reason I originally posted this question, was because I am not familar with this so called third type of IF statement, I have read other books, and it made no reference to it, I assume your right in what your saying about CASE, END CASE or maybe a FUNCTION could be used.

Has anyone else read the book?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Mar 2006 01:16
elseif?

FREE Automatic file updates for your distributed Games and Apps - see Program Announcements Forum - DBP Demo
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 19th Mar 2006 02:13
Hi CastleRustler

I double checked the book, cause I am a noob sometimes, but no it definately is as I mentioned in my last post!

Quote: "
Although nested IF statements get the job done, the general structure can be difficult to follow. A better method would be to change the format of the IF statement so that several, mutually exclusive, conditions can be declared in a single IF statement along with the action required for each of these conditions.
"

It then gives examples as above.
Any ideas anyone ? or am I just being a nob!!!!
Pheonixx
20
Years of Service
User Offline
Joined: 6th Oct 2003
Location: Columbus, Ohio
Posted: 19th Mar 2006 02:29 Edited at: 19th Mar 2006 02:30
elseif?

Haven't seen that command since QBasic. It is a combination of this...



in Qbasic you could do this...



If the condition wasnt' picked up by the IF or ELSEIF the compiler would just assume no action needed to be taken.

Ultimately you can not use ELSEIF anymore, and frankly you shouldn't.

http://ausukusa.breakset.com
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 19th Mar 2006 02:47
Hi Pheonixx

I agree elseif is not a command used by Darkbasic, I have just looked through the chapter a little bit further and came across another problem.

Quote: "
When writing a formal algorithm in which we wish to repeat a set of statements a specific number of times, we use a FOR...ENDFOR structure.

FOR 3 times DO
throw dice
add dice value to total
ENDFOR
"

Now what the hell is going on, I bought the book to learn Darkbasic not confuse me with commands that don't even exist. I assume I'm right in saying FOR....ENDFOR is not a command in Darkbasic, well it doesn't work in mine. HEEEEELLLLLLLPPPPPPPP !!!!!!
Pheonixx
20
Years of Service
User Offline
Joined: 6th Oct 2003
Location: Columbus, Ohio
Posted: 19th Mar 2006 02:54
wow, what on earth did you buy?

FOR has always been followed by TO, STEP and NEXT, I have never seen ENDFOR.

FOR SomeValue = StartValue TO EndValue STEP ProgressionValue
...
NEXT SomeValue

declaring a STEP value is completely voluntary, by default it is 1.

FOR X = 0 TO 100 STEP 10
PRINT STR$(X)
NEXT X

some languages like Qbasic do not require you to declare anything after NEXT, but for good practice you should always tell the compiler that information, I think it is required in DBP. NEXT what? NEXT X!

http://ausukusa.breakset.com
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 19th Mar 2006 03:00
Hi Pheonixx

I bought "Hands on Darkbasic Volume 1" from this website, I have just checked FOR.....ENDFOR in google it came up with a link to Microsoft Visual FoxPro 9.0 Language Reference.

Quote: "
The following examples demonstrate how FOR EACH is used to enumerate elements in a Visual FoxPro array, an OLE array, and a set command buttons assigned to an object array.

In the following example, a Visual FoxPro variable array is created and FOR EACH is used to display the contents of each element in the array.

Copy Code
DIMENSION cMyArray(3)
cMyArray[1] = 'A'
cMyArray[2] = 'B'
cMyArray[3] = 'C'

FOR EACH cMyVar IN cMyArray
? cMyVar
ENDFOR


In the following example, an instance of Microsoft Excel is created, and a new workbook is added. FOR EACH is used to display the name of each worksheet in the workbook. This example requires that Microsoft Excel be properly installed on the machine on which the example is run.
"


Maybe the book is just covering algorithms in general terms, I suppose I should really finish reading it, although it is pretty intense for me. But hey it's got me thinking! lol

Thanks for all your help!!!
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 19th Mar 2006 03:04
Quote: "
Executes a set of commands a specified number of times.


FOR VarName = nInitialValue TO nFinalValue [STEP nIncrement]
Commands
[EXIT]
[LOOP]
ENDFOR | NEXT



Parameters
VarName


Specifies the name of the variable to act as the counter. The counter keeps track of the number of times the Visual FoxPro commands execute inside the FOR ... ENDFOR loop. The variable does not need to exist before executing FOR ... ENDFOR.
nInitialValueTO nFinalValue


Specifies the initial and final values of the counter. Both nInitialValue and nFinalValue can be array elements.
[STEP nIncrement]


Specifies the amount to increment or decrement the counter value. If nIncrement is negative, the counter value is decremented. If you omit the STEP clause, VarName increments by 1.
Commands


Specifies the Visual FoxPro commands to execute. Commands can include any number of commands.
[EXIT]


Transfers control from within the FOR ... ENDFOR loop to the command immediately following ENDFOR. You can place EXIT anywhere between FOR and ENDFOR. For more information, see EXIT Command.
[LOOP]


Returns control to the FOR clause without executing the statements between the LOOP and ENDFOR keywords. The counter value increments or decrements as if ENDFOR was reached. For more information, see LOOP Command.
ENDFOR


Specifies the end of the FOR ... ENDFOR loop.
NEXT


Specifies the location to continue program execution after the counter value exceeds nFinalValue.
Remarks
"


Sorry pasted wrong quote in above !
Pheonixx
20
Years of Service
User Offline
Joined: 6th Oct 2003
Location: Columbus, Ohio
Posted: 19th Mar 2006 03:14
Feel free to clicky on my MSN or YIM buttom, I don't mind helping out young programmers pretty much all the time.

Unfortunately not enough people actually read books or even the forum before diving into coding the next MMORPG so it's pretty nice to be able to help out someone willing to do the footwork to learn stuff.

http://ausukusa.breakset.com
Ant
19
Years of Service
User Offline
Joined: 27th Nov 2004
Location:
Posted: 19th Mar 2006 03:26
Hi Pheonixx

I have just rechecked the review of the book, on this website and to my horror, it confirmed my suspicions, the first chapter is just an introduction to Algorithms.

It doesn't start covering Darkbasic Pro until Chapter 2. So I'm sorry guys my impertanant impatience, has wasted your valuable time, But hey it got everyone thinking. lol

Thanks for all your advice though !
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Mar 2006 04:58
Quote: "
Hi CastleRustler
I double checked the book, cause I am a noob sometimes, but no it definately is as I mentioned in my last post
"


no problem, I was just checking if dbp had that command because I forget.

please use code tags to show code, not quote blocks -thanks

to handle your crossbow too hi/low, L/R dilemma - just break height and l/r checks into 2 nested if checks...

psuedo code:


FREE Automatic file updates for your distributed Games and Apps - see Program Announcements Forum - DBP Demo

Login to post a reply

Server time is: 2024-09-24 19:28:50
Your offset time is: 2024-09-24 19:28:50