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 / How to load in levels in sequence?

Author
Message
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 26th Mar 2010 13:24 Edited at: 26th Mar 2010 13:29
My levels are textfiles and numbred like this: Level001, Level002,Level003...,Level050. How would I load them in sequence, after the previous level has been finished?
An example or some code would be greatly appreciated.

Thanx in advance

Cheers

Slayer rules!!! Yeaaah, man!
mike5424
17
Years of Service
User Offline
Joined: 30th Mar 2009
Location:
Posted: 26th Mar 2010 16:17
Text Files? Don't you mean .X Files? Anyway,
Etc.

Alot of people say not to use Goto though, And there are better methods but this one is simple

---
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 26th Mar 2010 16:36
Quote: "Text Files? Don't you mean .X Files?"

No, I really meant text files. Those text files store the positions of my models. So, I would need a method of loading them by filename, and in sequence. It's the only big issue that keeps me from finishing my game for Intel.

So, any other ideas? Someone?

Thanx

Slayer rules!!! Yeaaah, man!
empty
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Mar 2010 17:17 Edited at: 26th Mar 2010 17:17
You mean something like this?



Example call:
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 26th Mar 2010 17:18
You might get away with just a level variable, say IDLEVEL

Make it 1, and see if there's a level for it - pretty cheap but it should be enough.

IDLEVEL=1

Do

levfile$="Level"+right$("000"+str$(IDLEVEL),3)+".dat"
if file exist(levfile$)=1 then load(levfile$) else IDLEVEL=0

While IDLEVEL>0 and ALIVE=1
---Main Loop
Endwhile
Inc IDLEVEL,1
Loop

So, it'll make a filename string based on a level number (IDLEVEL), and if the file exists then it gets loaded, otherwise the game must be completed, and you need to start again.

Note this bit:

right$("000"+str$(IDLEVEL),3)

That will format the IDLEVEL to 3 digits, so you'd have to use 3 digits every time for the level filename - no biggie, it's easy to change - but personally I like to have a strict format in cases like this.


Health, Ammo, and bacon and eggs!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 26th Mar 2010 17:19
Hehe Empty, how you like my 1 line number formatter?

right$("000"+str$(IDLEVEL),3)


Health, Ammo, and bacon and eggs!
empty
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Mar 2010 17:27
I like, I like
luskos
19
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 26th Mar 2010 17:30
You start the game.Start New game.Load level 1.Play,play,play...
You are at end of it!I assume your levels contains start position of the player, object data and stuff like that.What you have to make is routine that free up resources when the level is cleared by the player, at the same time you put a loadscreen to hide what is loaded behind(actually is good to first put loadscreen and then call the cleaning routine).Then you start loading level 2, move player to start position at level 2 and so on until the very end.

What do you mean your levels are text files?Is everything in them readable in Notpad or Wordpad?If it`s not then they are text files because you leave them with *.txt, you can change to whatever you want.

I use matrix1 I/O for files and i`m not sure what are you using,but
with matrix1 i need to do something like this to load my level:


If i needed sufficient system for loading levels i would need to just watch over the current level.I need variable "current_level" which i need to increment every time the player finish the current level, just before my loading routine.If current_level = 0 means there is no level loaded, increment and go to loading routine to load level 1.And the above line can become something like this:


You no longer care which level the game is loading, you can be sure that when finish level condition is met, your game will inc "current_level" and the next level loaded is the right one.

You need just to rename your levels accordingly "level1.lvl","level2.lvl", etc.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 26th Mar 2010 17:41
Thanx @empty, Thanx @Van B, those examples helped me a lot! I had something simular written, but I mixed up the right$ with the left$. It was just a silly mistake, but those are the ones that are the most difficult to spot.

Cheers

Slayer rules!!! Yeaaah, man!
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 26th Mar 2010 17:55
@luskos:

Thanx to you too for helping. Yeah, my levels contain the object positions and stuff. And, altough they don't have the .txt extension, they're just textfiles, that you still can read with notepad. You should try that with your .lvl files too. Just open them with notepad, and you'll see a lot of text (scrambled or readable).

Cheers

Slayer rules!!! Yeaaah, man!

Login to post a reply

Server time is: 2026-07-27 01:06:17
Your offset time is: 2026-07-27 01:06:17