Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

Random-Depth Tree Creator/Editor

$
0
0
Edit (2024-04-18@2216ish)

I made a mistake. I've been running the Tree Creator over and over and it is *not* doing what I want. Essentially any Root Branch could branch differently from any other root branch but within any given branch all branches were the same.

In other words:

"You come to a Crossroad."

Now no matter what you do you have the same number of choices to get to an outcome.

If you go left you get three choices. If you turn back you get three choices. If you go right you get three choices. You get the point.

That's because I was generating the Random Number *outside* the loop.

Now I've moved it inside the loop so if you turn back that might be the final outcome. But if you turn right you might get four choices. If you turn left you might get two choices. If you go straight ahead you might get five choices.

I haven't uploaded it yet - the attached upload still contains the problem. I need to play with it some more.

Also, the whole Create Method in cNode is hack programming. I have no idea what I'm doing really. I just keep changing pluses to minuses and trying different things. As long as it exits without Stack Overflow I know I'm on the right track. Again, this is a one-time tool so it doesn't need to be perfect. It just has to give me a result I like eventually and it's doing that now.

I'll make another edit to this post with the updated source code after I play with it some more.

Made a few other small tweaks such as getting rid of the leading "000" in the textbox because that's the Mother of all Branches and isn't necessary.

Also too, the stuff I posted does work. There's nothing actually wrong with it except not being as random as I wanted.

============================

Original upload: Tree.zip

============================

This is a Tool I built to create random events in a game I'm writing.

The idea is to create a Tree having Random-Depth Branches.

Each Branch can branch off into different directions so that when an Event happens it can go multiple ways.

The "real" way to do this is to probably just create branches as you need them but I wanted something to kind of push me along.

Hopefully what I end up with content-wise isn't too contrived just to force-fill the Nodes.

It's a one-and-done kind of tool. Once the Tree is created that's it for that game. You never use it again.

Unless you want to create multiple databases or put multiple tables in the same database and each time you run the Tree Creator you have it fill a different table. You'll have to change the Table Name in the code every time you do this.

--------------

Edit: You could pretty easily add another textbox to the Tree Creator and have it create an empty copy of the Table with whatever name you enter into the textbox and then have the Tree fill that new table. I should have done that and probably will.

--------------

That would allow you to use the same game engine (you gotta write that) but have multiple versions of it: Steampunk, Cyberpunk, Post-Apocalypse, etc.

This applet is very bare-bones. It is fully functional though.

I added in the quality-of-life stuff I know I'll want. I'll probably make some tweaks to it here and there as I'm using it more extensively and find things I'd like to work better or easier or more efficiently or whatever.

But really it's just to get me the content for my game without spending any more time than necessary making the tools to make the game.

If you download the attached file then be sure to check out the Tree Editor *BEFORE* you create any Trees.

Every time you create a New Tree it wipes out the existing Tree. All of it.

So the first thing to do is fire it up, go to the Tree Editor, go to the "Branch to Node" Combobox and scroll down a few entries.

There are Nine entries filled in this so you can see how it works.

Also too, if there's an entry missing in the middle of a branch it will tell you. In fact, it will tell you ALL missing nodes.

But if you see something like:

"You walk into the forest."
"You see a bear."
"[Content is Missing]"
"YOU DIED!"

Then there's a missing bit that needs to be fixed.

Anyway, this is doing everything I need it to do (I think) and it doesn't choke.

I will caution you against putting in huge numbers for the Tree Creator.

I put in 999 for Starting Seed and 99 for Target Depth. Hours later it was in the 300's. That was when it was only writing to a text file. I hadn't done the db bit yet. That's on a Threadripper 3960x with very fast NVMe drives.

Because it's Random, you might end up with the largest tree possible for the numbers input or something very small.

For example, if you enter 50 for Starting Seed, that doesn't mean it won't roll a one and give you one branch with two nodes.

So you might have to do it a few times to get something you like which is exactly what I wanted.

I just roll until I get about the right balance between number of Branches and total number of Nodes.

I was looking for Nodes in the 3K to 5K range. Starting Seed of 75 with a Target Depth of 6 got me what I wanted after a couple rolls.

===============

About the game and why I'm doing it this way. And before I go there, this IS NOT the game. This is to create content for the game in case that wasn't clear.

This game isn't a "story". It picks Events at random and the player responds to them.

So one event might have the player in her office and the next Event might be the player in a dungeon with no coherant path from office to dungeon.

That's not driven by the Tree though. If you were to use this to build a game you could easily set it up so it doesn't pick events at random and events have to follow each other in a logical way.

I'm just having fun. :)

Lastly, I have "Tech Savvy" and "Booksmarts" that seem to be pretty much the same thing. I want six stats so before I go creating a bunch of content I need to think about that some more and figure out a stat that would be better to replace one of the two.
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>