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 / 2 dimensional array code problem

Author
Message
Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 15th Aug 2013 21:17 Edited at: 15th Aug 2013 21:20
I've created a 2 dimensional array and read data into it.
I then wanted to read it back out and a the values are showing 0.

Not sure what I am doing wrong.

Data Structure of Player Base Array
Array Name: PlyBase
Array Size: 9,4
Array Structure - Row 1 - Number of Lines to Draw
Row 2 to X - holds draw data
PlyBase(9,4) = Number of Lines in Draw

Starting Data:
8,0,0,0
0,-5,-8,3 `Arrow Point Left
0,-5, 8,3 `Arrow Point Right
-12,3,12,3 `Base Top Line
-12,12,13,12 `Base Bottom Line
-12,3,-12,12 `Base Left Side
-3,3,-3,12 `Arrow Left Side
3,3,3,12 `Arrow Right Side
12,3,12,12 `Base Right Side

Remend
Data 8,0,0,0
Data 0,-5,-8,3 `Arrow Point Left
Data 0,-5, 8,3 `Arrow Point Right
Data -12,3,12,3 `Base Top Line
Data -12,12,13,12 `Base Bottom Line
Data -12,3,-12,12 `Base Left Side
Data -3,3,-3,12 `Arrow Left Side
Data 3,3,3,12 `Arrow Right Side
Data 12,3,12,12 `Base Right Side

` Loading PlyBase Array

Dim PlyBase(9,4)

For Row= 1 to 9
For Column= 1 to 4
Read PlyBase(R,C)
NEXT
NEXT

X=350 : Y=200 ` Location of Base Dim Draw
` Base Dim Drawn

For FNX = 2 to 9 `PlyBase(1,1)
Print "FNX";FNX
Print "PlyBase 1 -";PlyBase(FNX,1)
Print "PlyBase 2 -";PlyBase(FNX,2)
Print "PlyBase 3 -";PlyBase(FNX,3)
Print "PlyBase 4 -";PlyBase(FNX,4)
Wait 300
NEXT
Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 15th Aug 2013 21:19
Okay so the code snippet I did didn't work right. How do I create a code snippet?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Aug 2013 21:30
Quote: "How do I create a code snippet?"


Step 1: Copy your code to the clipboard in the usual way.

Step 2: Click somewhere in the Post Forum Message box just in case.

Step 3: Hit the code button.

Step 4: Paste your code from the clipboard.

Step 5: Hit the code button again.

With luck you should see a code box with your code in it after you post the message.



Powered by Free Banners
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 15th Aug 2013 22:31 Edited at: 15th Aug 2013 23:29
Compare your code to this snippet. I believe this is what you’re trying to accomplish.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 15th Aug 2013 23:50
Your problem is here..



Can you see what the issue is?

Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 16th Aug 2013 06:53
Thanks guys.

Thanks Mobiius. Yep, I see it. *Smacks hand to forehead*
Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 16th Aug 2013 08:11 Edited at: 16th Aug 2013 08:11
Now that I've moved beyond my error...
Lets try for a code snippet again.



Most everything in this game is symetrical(sp?). The most efficent way I can think of drawing the assets is the 3rd example.

If there is and easier way to draw them I'd would appreciate your ideas.
Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 16th Aug 2013 08:13
Yea, the Snippet worked.
Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 16th Aug 2013 08:21
Yep, Wicked X. That was just about what I was tring for.

The first line of Data is to tell me how many lines of draw data is in the array. Is there a command to check how many rows of are in a array?

I could eliminate a row of data if there is.
Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 16th Aug 2013 08:48
Okay, This is how I can count the rows a array. (Knowing the there are 4 columns.



Anything simplier?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Aug 2013 10:27
Quote: "Okay so the code snippet I did didn't work right. How do I create a code snippet?"


[[b]code lang=dbp][/b]paste your code here[[b]/code][/b]

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Aug 2013 11:44
Anruth

Try this:



Don't forget that array indexing starts from 0 for each dimension of the array. The Help file entry for array count is unnecessarily opaque in my opinion.

Glad you got the code snippets working (TheComet's suggestion is a nice refinement ).



Powered by Free Banners
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 16th Aug 2013 20:22
Quote: "If there is and easier way to draw them I'd would appreciate your ideas."


There is little reason to resort to using DBPro’s 2-D graphics functions. It would be much better and faster to load an image and paste it.

Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 17th Aug 2013 07:32
For the Space Invaders type/clone game I want to create, I like the look and feel of the draw commands.

I'm going to break it down into tutorials/lessons for some kids I'm teaching to program. So I want to draw the graphics at first instead of teaching them other software programs needed to make sprites ect. That will come later.

I want them to have a strong handle on DBP/Programming before splintering them off into graphics. They need to walk before they run.

Thats what is so great about DBP, It's easy to learn and free or low cost solution for kids. Not to mention the ability to build .exe files. (Singing to the Choir)

Plus I need the practice.
Anruth
15
Years of Service
User Offline
Joined: 20th Dec 2010
Location:
Posted: 17th Aug 2013 07:34
Thanks Green,

Your solution is cleaner then mine. I'll be using it.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Aug 2013 12:50
You're welcome.



Powered by Free Banners
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Aug 2013 21:53
I went through your code and edited it a bit:


A few pointers:
You had columns and rows the wrong way around.
You did not make use of array field 0.
I don't like this plybase array (which I renamed "defender") at all. It gives no indication of what type of data it holds, in what order, or in what format.

Here's an idea of a format that would be more intuitive:




The gluteus-maximus mammary-gland formally known as OBese87.

Login to post a reply

Server time is: 2026-07-07 00:07:42
Your offset time is: 2026-07-07 00:07:42