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 / Organizing and separating the script?

Author
Message
Tobias_Ripper
13
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 8th Apr 2013 19:51 Edited at: 8th Apr 2013 20:27
Here is the task.

For small games it is easy enough to write all code in one single file. But for larger projects I would like to have a little bit of organization by means of separating code with all actions for different levels into separate code files. So the main script will initialize the basics for running a 3D game along with the main game loop with Main Menu, Game Over screens and so on and things like levels, settings, controls, would be loaded from a separate file?

For instance (something that would look like this)

Note: NOT REAL CODE




Q1) How can I achieve the loading of a script with the levels from a separate file?
Q2) Does anything need to me re-declared like game/screen settings?

In conclusion this feature will be used as a save/load point. Game is saved only when the level is completed.

Isenstadt Studio: http://isenstadtstudio.com/
Composers Page: http://milothatch.isenstadtstudio.com
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Apr 2013 20:50
To do what you're thinking you'll need a scripting engine like Lua. However, you'd be better coding your game engine to handle "levels" and make it a self contained file which describe how to do everything needed for that level.

Kind of like how the unreal engine works. Each UNR (or whatever it's called now) is a self contained archive containing level geometry, textures, sounds, scripts, UIs all in the same file. It's the game engine which takes all that and displays it on screen or whatever.

In my game engine, everything is based on XML, so at the start of my code, I have a function which automatically opens default.xml. This xml file will contain the main menu interface, how the 3d scene for the menuscreen will look like, what music to play, and what each menu option will do. If I click on the "Play Game" button, what the engine is actually doing is calling a few pre written functions to remove the existing level/UI, then open another xml which contains everything needed for level 1 of my game.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 8th Apr 2013 21:46
i think he wants to chop the code in several smaller pieces for easier navigation if the project has lots of code.

Your project file is a .dbpro file and all your source code files are .dba files. You can have many .dba files.

On the left side of the ide you have treeview with all .dba files included in the project. There you can add additional files: right click on project name->add new file.

NOTE: All the code in those additional files need to be organised into functions or gosubs and then from the main .dba file you just call those functions/gosubs

Tobias_Ripper
13
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 8th Apr 2013 21:53
Hmm so the file tree to the left is only for functions huh? I kinda figured the perhaps there would be a command to load the script from a separate .txt file which would act as if you copied and pasted code from one file to another only done so automatically.

Imagine that you have 2 files - one us the project file which contains the main game loop. and another contains a dark basic code which simply shows a sprite panning from left to right.
Instead of writing the walking sprite code in the main loop, you would write LoadScript = (SpritePanScript.dba) and it would automativally insert that script and execute whatever was in it.

Perhaps a txt file.

Isenstadt Studio: http://isenstadtstudio.com/
Composers Page: http://milothatch.isenstadtstudio.com
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Apr 2013 22:13
You cannot load code into the engine at runtime. Period.

You can add that code into the project at design time. The best way is to load the additional dba file into the project using the editor. But you can also #include an include file as well.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Tobias_Ripper
13
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 8th Apr 2013 23:43
Alrighty then No dynamic script laoding. Got it.

Are there any flexible script organizating features in DBP? Like if you write a game with 4000+ lines of code it will eventually become really hard to navigate in the code. Are there any types of code folders or tags which would put the included code into a container which could be minimized or maximized? Just ease up the navigation around.

Isenstadt Studio: http://isenstadtstudio.com/
Composers Page: http://milothatch.isenstadtstudio.com
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Apr 2013 23:58
It depends on which editor you use, there are about 7! I personally use EditorNew.exe from within the editor folder. It has a code view panel which allows you to jump to functions, types, labels and variables. It also allows function/loops/comment/type block folding amongst other things.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Tobias_Ripper
13
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 9th Apr 2013 00:04
Hmm, was it a custom made edditor or did it come with the DarkBasicPro Package? I have the CD lisence for Dark Game Studio and I have it updated. For now I have been using the editor which came deafult. (The one that got short-cutted to my desktop)

Isenstadt Studio: http://isenstadtstudio.com/
Composers Page: http://milothatch.isenstadtstudio.com
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 9th Apr 2013 01:25
It's an editor which comes with DBP. (But strangely not the default)

Check your DBP folder for it. (The Game Creators\DBPro\Editor\EditorNew.exe)

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Apr 2013 01:31 Edited at: 9th Apr 2013 01:32
Personally speaking, I'd recommend Indigo ; it is in beta phase of development, but I personally find it more pleasing, modern and well organized compared to the official editor; it is also more frequently updated. With it (judging by my donation version) you may organize your projects into files and virtual folders much like windows explorer.

Tobias_Ripper
13
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 9th Apr 2013 01:33
Oh, thank you TGC, for multiple editors. This is great to know. Thanks for the tip too guys.

Isenstadt Studio: http://isenstadtstudio.com/
Composers Page: http://milothatch.isenstadtstudio.com
Tobias_Ripper
13
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 9th Apr 2013 05:14 Edited at: 9th Apr 2013 08:46
Alright, I came home a few minutes ago and I checked out the NewEditr.exe and actually this is the one that I've been using thus far. It was automatically linked to as my shortcuts.

Guess bookmarks, comments and inserting breakpoints are the only core ways of organizing navigation around the script. Alright, that's thorough enough.

Isenstadt Studio: http://isenstadtstudio.com/
Composers Page: http://milothatch.isenstadtstudio.com
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 9th Apr 2013 13:49
Don't forget you can navigate through your source using the items in the code view tab, like this..



I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]

Login to post a reply

Server time is: 2026-07-08 12:46:52
Your offset time is: 2026-07-08 12:46:52