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 / Help with Nested For...Next Loops

Author
Message
the capitaine
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location:
Posted: 19th Nov 2008 08:50
Hi, everyone!

I'm a longtime DBPro Owner, longtime forum lurker, and shorttime coder w/this software. I've been making excellent progress on working through tutorials and trying to cobble together my own simple games. However, I've hit something of a brick wall with a bit of code and weird behavior that has me stumped. I'm sure all of you experienced folks will see in two seconds what has had me argh!ing for a couple hours now. Anyhow, here's the code in question:



Now, as background, I'm using a series of data statements to show the order of tiles on a small map I'm using for my prototype and the included code is supposed to go through those statements and deliver those tiles on the screen. The tiles are in their proper places and I thought all was well... until I discovered that my MapSprite variable is being mangled in the process. Seems like the first two 'columns' of my map tiles seem to have the same sprite # when I run a little code to check their ids. Each tile is supposed to have a unique, predictable MapSprite value.

I'd appreciate any help you can give! Thanks in advance.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 19th Nov 2008 11:58
As you are probably calling the MapSprite variable from outside of that function, are you sure that you have made it a global?
Others than that, it all looks correct, so I can't tell you what could possibly be wrong apart from the scope of the variable.


-> Oh, come on...
the capitaine
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location:
Posted: 19th Nov 2008 16:27
Thanks, Rudolpho, for helping me resolve this issue! Reading your post got me away from examining the loop for the problem and taking a peek at the code I was using to verify the sprite numbers and tile positions. Turns out *that* code was gummed up and this loop was working as intended. It also turns out that despite going over TDK's excellent tutorials--the one on building menus really helped introduce me to using sprites-- I still have a lot to learn about how sprites work, especially sprite collisions.

If I may piggyback on my own original post, I was wondering if I could ask another quick question. My code is starting to get a bit long. It's still fairly organized but I'm wondering at what point DB coders start chopping pieces of the code up and having them either included as external files or begin using some file access commands to cut down on the amount of text on the page? What are the basic best practices for when to do this? I'm feeling an urge to do that sooner rather than later because of the inconvenience of scrolling all around but at the same time I'm worried bugs like I've already encountered may become even harder to suss out if code is compartmentalized across a lot of different files. Thanks again, to this great community for any help w/this and forgive me if I'm violating a posting rule by posting another question atop my earlier one!

Login to post a reply

Server time is: 2024-09-27 22:34:13
Your offset time is: 2024-09-27 22:34:13