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.

AppGameKit Studio Chat / Multiple Level Loading via text file?

Author
Message
Amon
9
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 18th Dec 2021 01:44
I'm making a simple puzzle game in 3d. Each layout of the puzzle is loaded via a text file. What would be the best solution to having 100 levels that are loaded via a text file? Would I have 100 different text files or just one text file that loads each level when the level is up?

How would I do the latter? How do I separate the levels data in a text file and load it on demand when the level is needed to be set up?

Thank you all.
Win 10 Pro - AMD RYZEN 9 3950X 64GB DDR4 - RTX 2080 SUPER
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 18th Dec 2021 02:43 Edited at: 18th Dec 2021 02:55
can you give an example of a "simple" level's data?

regardless, IMHO, i see (literally) loading each level separately as "old fashioned". ie, when RAM mattered more.

i would consider loading it all at once and storing it. even better, to simply include the level data inside the executable/project file(s)

(see BuildMap() and AddRow() functions HERE)

that being said, if you're intent on loading each level from a single data file, and given what AppGameKit can (and can't) do when loading data from files, all i can think of is formatting the file something like:


then, when it's time to load a level, open the file, read each line and check the first character.

if it's a >. it's a "level header" so grab the rest of it to see WHICH level (1, 2, 3...).

if it's the correct level, read the subsequent lines while continuing to check for > which would signify the end of the level data.

if it's not >, parse it as level data.

if it IS >, end the process. the level's done loading.

reading potentially HUNDREDS of lines each time you want to load a level from a single file is inefficient, at best, but i can't think of another way to "load on demand" from a single data file.

DBPro has/had File Pointers (at least as an IanM Matrix command?) which would help here but i don't think we have anything like that in AppGameKit?
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Dec 2021 02:57
Quote: "but i can't think of another way to "load on demand""


use XML type marker tags, "<LEVEL_1>level data here</LEVEL_1>" then either search the forum for a xml parser (there's a few) or read the entire file to string and "string find" for the level marker tag and "mid" from the start point omitting the tag (what the XML parsers do), still inefficient but faster than parsing line by line over and over and you only need to load the string once.... probably better to parse it and load it into a type array at project load and dump the string
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 18th Dec 2021 03:04 Edited at: 18th Dec 2021 03:07
.toJSON/.fromJSON is better than parsing but the first time i read the OP, i guess i hung onto "the latter" part as the (only) question (despite the previous ?s ).

i still want to know what the "simple" level data is like.
PartTimeCoder
AGK Tool Maker
8
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Dec 2021 03:55 Edited at: 18th Dec 2021 03:59
Yes, the json route is definitely the way to go, I over looked that aspect.


a crude example for a grid based level system


LevelData.json
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Bored of the Rings
User Banned
Posted: 18th Dec 2021 07:34 Edited at: 18th Dec 2021 07:35
@Amon-would be good to see your level data example.

Many ways to do this, the old fashioned 8 bit way is DATA / RESTORE statements in your program and read them in at will ,but not good for 100 levels. XML/JSON is a good way to go. Other ways are reading into memory and deleting the memory when done with the leve i.e. txt files to memblocks.

What I did recently was read some files in e.g. .txt etc put them into memory then save out as binary files then remove the code that reads in the original format and just read in the binary files.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Dec 2021 22:52
The beauty of JSON is it will happily throw away variables that aren't in your type.


So both tA and tB can be loaded from the same JSON file. In the case of tB it will throw away the "a" portion of the JSON file/string
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 20th Dec 2021 01:01 Edited at: 20th Dec 2021 01:02
I do separate text files for each level and write a custom parser for loading them. That's assuming you're not making levels in the scene editor.
Amon
9
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 21st Dec 2021 05:05
Hi, thanks all for the replies. Here's a little bit more clarification on what I'm doing.

The game is in 3D. The outer wall of the puzzle will be a series of GreyCubes. Each cubeID for the GreyCubes will be 1. RedCubes 2, OrangeCubes 3 and so on. Within the play area 2 sets of each non grey coloured cube will be placed and the goal is to match them up. Red to red, yellow to yellow etc. Any non matched coloured cubes that collide will result in the loss of the level.

A simple example of how I will be loading th elevels, this is going to be contained in the level.txt/.json file, is below.

1 = Grey Cube
2,3,4 and onwards represents the different coloured cubes.

Example Level.txt file:

1111111111
1000000001
1000000021
1000000011
1000000001
1000000001
1100000001
1200000001
1000000001
1111111111
Win 10 Pro - AMD RYZEN 9 3950X 64GB DDR4 - RTX 2080 SUPER
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Dec 2021 05:12 Edited at: 21st Dec 2021 05:15
Quote: "Example Level.txt file:"

that's what i expected and why i don't understand the need for loading anything vs keeping it in-code. from the TD template:

BuildMap() could easily become BuildMap(ThisMap) followed by a buncha If or Case statements (which, if i continue the template, it will).

but, as you wish. it's your baby
Amon
9
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 21st Dec 2021 05:36
Thank you Virtual Nomad. I kindof got it working:

Win 10 Pro - AMD RYZEN 9 3950X 64GB DDR4 - RTX 2080 SUPER
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Dec 2021 06:49 Edited at: 21st Dec 2021 06:51
a couple of things (sorry, i cleaned up/formatted things a little differently):

this shows how might use the function to build various maps (ie, map 1, 2...)

...in your code, you are adding Row 5 multiple times (tho you are not using Row at all in your AddRow() function).

then, in your AddRow():

your for tgc loop seems to be positioning everything in GreyCubeList over and over (and over), LEN(Data$) many times?

if i'm reading it right, why not just position it as you read it in? IE:

anyway, glad to help (hopefully my responses aren't too confusing )
Amon
9
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 21st Dec 2021 08:12 Edited at: 21st Dec 2021 08:24


All I get is a diagonal line of cubes not even close to looking like the setup.
Win 10 Pro - AMD RYZEN 9 3950X 64GB DDR4 - RTX 2080 SUPER
EdzUp
21
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 21st Dec 2021 08:25
I would go the XML route this is the one I use for Star Rogue, in each system you have things like:
[Code]
<Header>
;System details in here
</Header>
<Data>
<Planet>
...
</Planet>
</Data>
[/Code]

I then parse the file at load time for relevant information and on the start of each block set the mode so if it's a planet it reads in the data till it it's the end /Planet tag then stores that in a planet array. It does this for everything in the game.
-EdzUp
Patreon: https://www.patreon.com/EdzUp
Buy me a coffee:https://www.buymeacoffee.com/EdzUp
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Dec 2021 19:19 Edited at: 21st Dec 2021 19:21
You could do this

or you could put that literal in a file and use levels.load(filename)
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Dec 2021 20:17 Edited at: 21st Dec 2021 20:23
@amon, this is about as clear as i can describe usage:
note "3" which is the green cube. top-left on map 1, bottom right on map 2:


i'm not sure how you were getting diagonal lines but i noted that you still weren't using Row which is the reference for z positioning of an object in AddRow().

anyway, run that. hit 1, 2 to choose a map and note the changes made (if any) to "map" out the level.

otherwise, feel free to try the other methods that are being suggested.
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 21st Dec 2021 21:41
So if you want to go old school you can use a tile system, there is a great video of how efficient they can be.

This is all the code for Super Mario Brothers World 1-1:


Check out the presentation by Kevin Zurawel called Game Development in Eight Bits:
https://www.youtube.com/watch?v=TPbroUDHG0s
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Dec 2021 21:47 Edited at: 21st Dec 2021 21:47
Amon
9
Years of Service
User Offline
Joined: 30th May 2014
Location: Shropshire, United Kingdom
Posted: 22nd Dec 2021 18:19
Wow, Thanks all for the positive replies. Especially @Virtual Nomad.
Win 10 Pro - AMD RYZEN 9 3950X 64GB DDR4 - RTX 2080 SUPER
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 23rd Dec 2021 10:29
You've been convinced to hard-code the level data within the exe and there are some good reason why you should. There is no right or wrong way, but now I'm going to give you some good reasons why you might prefer to have each level as a separate data file:

If the data is in the exe:
You can't release the game until all levels are created.
You have a fixed number of levels.
Any errors in one of the levels means you have to update and redistribute the entire exe

If the levels are separate data files:
You can release the game early with a small number of levels and add to them at any time.
You can keep adding levels for eternity - assuming your game is popular enough (think Candy Crush).
To change a level for any reason is simply a matter of changing a single data file - the exe remains unchanged. And if your levels are loaded from a server then that data file is the only thing that needs to change.


jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 24th Dec 2021 14:36
@VN haha awesome I obviously need to start following over there
monotonic
17
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 24th Dec 2021 17:53
I second Scraggle's points, it is much better to use data files for this. Obviously, prototyping as hardcoded level data is easier, but for production, I would strongly recommend going with the data files approach.
All programmers are playwrights and all computers are lousy actors.

Login to post a reply

Server time is: 2024-02-24 02:49:43
Your offset time is: 2024-02-24 02:49:43