Learn to Program 2D Games (Book)

Blitz3D Forums/Blitz3D Beginners Area/Learn to Program 2D Games (Book)

djstevenson(Posted 2005) [#1]
Begginner.

On page 295 of the book it gives you a program to type in or run (MultiArray). It says you will see the names starting with the first row. Then it says try altering the iNameRow loop to print out the female names first( hint: you'll need to use that STEP command!). I have been trying to use the STEP command at the end of the iNameRow loop. But cannot figure it out?. If i put step 1 at the end of the line it just prints the whole lot out and if i put step 2 at the end of the line it prints just the male names?. I would like now how to do it using the same example code in the book please and hopefully an explanation.
Help Please
Thanks.


DH(Posted 2005) [#2]
Simply advance the start of the loop.

If the loop starts at 0, then start it at 1.

For example:

This will print all
For X = 0 to 10 step 1
print Names$(x)
Next

This will print the men?
For X = 0 to 10 step 2
print Names$(x)
Next

So this should print the women
For X = 1 to 10 step 2
print Names$(x)
Next


Or am I way off?


djstevenson(Posted 2005) [#3]
This is the code from the book.

; Initialize Blitz Basic to 640x480 resolution
Graphics 640,480

; Dimension our NameArray
Dim NameArray$(2,4)

; Assign our values to the array
NameArray$(1,1) = "John"
NameArray$(1,2) = "Joe"
NameArray$(1,3) = "Mark"
NameArray$(1,4) = "George"
NameArray$(2,1) = "Sally"
NameArray$(2,2) = "Betty"
NameArray$(2,3) = "Lorelei"
NameArray$(2,4) = "Anne"

; Set up the vertical control variable
iTextY% = 0

; loop from 1 to 2 (rows)
For iNameRow = 1 To 2
; loop from 1 to 4 (columns)
For iNameColumn = 1 To 4
Text 0,iTextY,NameArray$(iNameRow,iNameColumn)
iTextY = iTextY + 16
Next
Next

; wait for a keypress
WaitKey()

; end the program
End


tonyg(Posted 2005) [#4]
If anybody is looking for it, it's page 53/54 rather than 295.
I can't see how step can be used to get the female names rather than changing iNameRow to state...
for iNameRow = 2 to 2

The problem is Krylar builds on code first listed on page51. This code has alternating male/female names.
However, the multidimensional code example has changed the order to all male and then all female.
<edit> If you're working through that book (it is VERY good) there are a couple of errors listed here...
SNAFUs


Rubiks14(Posted 2005) [#5]
the only way i could think to get it to work would be to reverse iNameRow like this
for iNameRow = 2 to 1 step -1

maybe that is what he meant by having to use the step command...but still he should have hinted that u might have to change the numbers


djstevenson(Posted 2005) [#6]
Thankyou it was 53/54 sorry. The way it states the page No's.
It's very tough being a beginner especially learning from books, but thanks to everyone.


scribbla(Posted 2005) [#7]
is the book any good, as my 12 year old wants to get into blitz and im looking for an easy to follow book (for me as well)


LineOf7s(Posted 2005) [#8]
Apart from the couple of SNAFUs mentioned above, yes, the book is a very good foundation for learning Blitz (whether Blitz Basic (2D) or the 2D part of Blitz3D).

Add to that the code archives and forums, and by the time you're at the end of the book you'll be quite advanced.

Then maybe you can start on 3D. ;o)