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 / Loading only one block when there's supposed to be five...?

Author
Message
Yodaman Jer
User Banned
Posted: 16th Jun 2010 05:45
Recently I've gotten back into programming with DB (I've been concentrating on learning C++/C# the last couple of months with virtually no motivation to continue studying them), and today I thought I'd kick off a project with a basic test engine for a game idea I've been working on since forever. All I did was write two text files; one called Setup.txt and level1.txt. After manually typing in all of the information in both of those files (it was easier to do that then write a routine in my program since my program won't need to do that when it's finished), I created the loading routines and a cery basic Do...Loop to move my camera around five blocks that were created from a file. The problem? There's only ONE block!

Here's what the level file looks like...


That was quite annoying to type out (thank God for copy>paste!).

My Setup.txt file...


And my source code:


It's very messy because this is only a test game engine. I hope to test all of my ideas out with it to make sure everything works, then I'll start the project yet again and optimize everything. That's how I've done it in the past, anyhoo.

So what's wrong? Why is it only creating the one block when there's supposed to be five? Is there something wrong with my LoadLevel: subroutine? I'm sure the answer is yes.

Here's what you'll need to do to run this program...

Create a new folder on your desktop. Name it whatever. Go inside of it and create a folder called "Data". Then inside of that folder, create a new text file and copy the Setup.txt information into it and save it as "Setup". Go back to the main folder and create a new one called "Levels". Inside of that one, create another text file and copy the contents of the "level1" file into it and save it as "level1". Then just simply copy>paste the source code into your editor, save it "test.dba" and run it.

Sorry to make it complicated like that, but I don't have time to make an executable.

If anybody can help me out with this I'd greatly appreciate it. I know this should be fairly simple (and it is), but this weird glitch is annoying me. Especially since I've done this in the past without any problems.

Clicky the piccy to access my blog.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th Jun 2010 07:12
I noticed that the level file is missing the ObjPath$ string for the next 4 blocks. Whatever 'invalid' is for, that's what's missing, so:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Yodaman Jer
User Banned
Posted: 16th Jun 2010 08:11 Edited at: 16th Jun 2010 08:19


Er...heh heh, yup, that was the culprit. Thanks Sasuke!

I really have to learn to double-check such things as that...

Next time I have a problem, I'm going to put off posting here for a couple of days...that's something I've always struggled with.

Thanks again!

EDIT:

"invalid" is there just for the moment. It will later be replaced with an actual object file path which my engine will then use to properly construct levels.

Clicky the piccy to access my blog.
Yodaman Jer
User Banned
Posted: 16th Jun 2010 20:09 Edited at: 16th Jun 2010 21:21
So I've got a couple more questions that aren't really related to this, except for the fact that it uses external level files.

In my game, I plan to have Sign Posts that gives the player tips and hints for the first three or so levels. I'm wondering if I can somehow store the sign's text inside of the level file itself and somehow read it back into the program without using too many variables. Has someone done anything like the following before? It uses an array (not yet experimented with in my program):



I'm thinking that would work extremely well. I don't see why it wouldn't, except that the 255 character limit might prove to be an obstacle later on. I doubt it though.

Another obstacle might be something to do with loading the level information into the program. When my program loads in blocks, it looks like this right now:



A problem I might be spotting already is that the program is constantly looping the file to read in the proper information to then create the cubes. If I keep the BillSign$(0) variable inside of that For...Next loop, will it keep overriding those variables needlessly and thus perhaps slow down the loading process? Is there a way that I can load the blocks and other objects in first, then the signpost text? Or should I just forget this idea and hard-code the signpost's contents in the engine itself?

Thanks to any and all who respond!

EDIT:

I was right. Keeping the BillSign$ variable inside of the For...Next Loop was a bad idea. Placing it just outside of the "Next CreateBlock" fixed it and the text displays perfectly. Now I just have to make it use an array and I'll be set to use this setup.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Jun 2010 23:17
Why not read the data in when you reach the sign, therefore negating the need to hold redundant signpost data in memory?

My signature is NOT a moderator plaything! Stop changing it!
Yodaman Jer
User Banned
Posted: 16th Jun 2010 23:31
I'd have to have other files for each sign then, wouldn't I? That would work out better in the long run, I suppose, but I'm not sure.

Actually, the more I think about it, it makes sense.

Say the player goes up to the sign and presses "A" to read it. One A has been pressed, the program goes into a single subroutine which does the following:

Checks which signpost the player is "reading"
Loads the appropriate file for that specific signpost
Displays the text in a While...EndWhile loop, then when the player presses A again, it exits and returns to the main program loop.

The reason I'd have to use a While...EndWhile loop is because the text would only flash on the screen for a second if it's not contained in its own loop. It's a stupid bug that annoys me because I know a programmer shouldn't use a loop within a subroutine that's called from the main program loop, but I don't have any other ideas. What would you recommend?

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 17th Jun 2010 00:42
Quote: "What would you recommend?"

Precisely what you've just said.

My signature is NOT a moderator plaything! Stop changing it!
Yodaman Jer
User Banned
Posted: 17th Jun 2010 08:07
Awesome. I'll try something out tomorrow and let you know how it goes. I imagine it will work just fine, unless I really manage to screw something up.

Yodaman Jer
User Banned
Posted: 18th Jun 2010 01:28 Edited at: 18th Jun 2010 01:34
Well, I haven't had a chance to test out the signpost thing yet, because I've been concentrating on getting the bare-bones of my custom level editor to work.

Basically, I've spent the last 3+ hours staring at this, trying to figure out why it won't compile:



I keep getting an error at this line:


Apparently, the program can't find the "ObjAttTrans" field from my Type variable. Why? It shouldn't even be touching on my SaveLevel routine yet, but I guess it does have to compile it, eh?

Anybody have any issues like this before?

EDIT: Gah! Nevermind. It turns out I was declaring my arrays and types backwards. I forgot that you had to first declare the type, THEN the array as the type variable. Whoops. :-\

I posted a similar question in the Posting Competition over in GC, but wasn't getting any responses which is why I posted here. But of course after posting here, I got an answer.

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 18th Jun 2010 01:36
You're declaring your types wrong.

Try this...


You don't need to do the 'As Integer' As your variables are integers by default.
You don't need to do the 'As Float' As you append the variable name with #, which tells the compiler it's a float.
you don't need to declare typed variables 'Global Variable' as arrays are always global.

My signature is NOT a moderator plaything! Stop changing it!
Yodaman Jer
User Banned
Posted: 18th Jun 2010 01:41
Ah yes, you caught my redundancy.

I realized that after I posted the code snippets and got everything to finally compile. I haven't programmed in about 6 months, so it appears as though I forgot some basic facts, i.e., arrays are always global and that I don't need to declare everything "as integer/string/float". And yet I still feel like I'm doing so much better than ever before.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 18th Jun 2010 03:05 Edited at: 18th Jun 2010 03:06
Quote: "I don't need to declare everything "as integer/string/float""


Though you might as well get used to it since you have to in every other language, especially when it's other data types. Unless of course, you'll only ever use DBP.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Yodaman Jer
User Banned
Posted: 18th Jun 2010 04:44 Edited at: 18th Jun 2010 04:45
True. I don't really see myself using anything other than DBP, unless I upgrade to DarkGDK and start going the C++ route. I'm also thinking of giving XNA a shot, but that's another subject for a different thread.

Yodaman Jer
User Banned
Posted: 29th Jun 2010 20:47
So my level editor is nearly complete (in terms of all of the functions I need for file saving/loading and object deleting/creating), and I've encountered a very strange bug.

In my level loading routine, I have the program read-in the file and load the proper 3D model with a variable named ObjPath$. Normally, this would logically work, yet it's not working at all for me. I have to type in the full file path, which completely defeats the purpose of using a variable that can be changed to load in different models.

Here's the code block:



Whenever I try to load a level file, it stops, crashes and says "Error on line ###, file doesn't exist". (This line:
) It's talking about the ObjPath$ variable, which after going in and inspecting the level file itself I KNOW contains the proper information. The only way I can get this to work is if I type in the full file path in "" marks, which as I've said completely defeats the purpose of using the string variable. What's wrong with it? Is this a normal bug?

Does anybody know how I can fix/get around this?

Thanks to any and all who respond!

P.S. Full source code, if it helps...



Login to post a reply

Server time is: 2026-07-25 08:29:25
Your offset time is: 2026-07-25 08:29:25