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.

Code Snippets / [DBP] - Simple RPG Branching Menu

Author
Message
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 29th Oct 2012 20:32
This is just a sample of how to design a very simple, text-based menu using only a few variables. One of the cooler features I implemented is the hold timer that allows you to move up/down the list more quickly. Besides that, not much going on.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Oct 2012 12:34 Edited at: 30th Oct 2012 14:21
You need a flag that prevents it from detecting the spacekey multiple times before it's released. Whenever I tried to go back to a previous menu, it'd just clicked right back.

A large problem with your system is that it's not very flexible. You'd have to make another IF block every time you wanted to add a new menu or submenu.


I wrote this up for you. It's not intended to show up your code, but hopefully demonstrate another, more flexible, method for a similar type of menu system by using arrays. It might look like a lot of complex code at first but it really isn't.


"You're not going crazy. You're going sane in a crazy world!" ~Tick
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 30th Oct 2012 19:16
No, by all means, it's great to see someone with a better approach, and great that the snippet is publicly available.

You gonna attach a license if I use that commercially? You wanna give me some payment info? I'm scrapping my old code.
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 31st Oct 2012 00:30
Huh, after playing around with it, I did notice one thing that confused me:

Why is isSelected casted as an integer? Surely it shouldn't ever be anything other than 0 or 1?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 31st Oct 2012 03:06
You're right, isSelected should probably be a boolean. And the code is free public domain.

Also, you might want to think about showing some kind of transition between the menus. It'll help users know whats going on better than just flipping immediately between one menu and the next.

Here's an example:
http://forum.thegamecreators.com/?m=forum_view&t=183122&b=6

Now that code would need a major rewrite to work with the code I've posted above, but you get the idea.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 31st Oct 2012 22:21
Okay, I thought so. Thanks very much, and if it does come down to it and I'm in a position to turn a profit, I will definitely credit you.

Yeah, I get it. I might design something like that, but some of the best RPGs there ever was don't really have noticeable transition effects.
Duffer
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 2nd Nov 2012 10:35 Edited at: 2nd Nov 2012 10:50
@ Phaelax,

Thanks for this code - presumably much of it can be hacked out and used in a nodetree type application?

[edit]

Looking at deleting items as well (and a function for that) how then do you keep track of the various items/nodes ids?

What if you actually then go an sort the array?

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 2nd Nov 2012 19:50
What I did is get the name of the selected item and match it against your target. I thought that was a little iffy too. If you wanted, you could easily just add a variable ID to the type and check that for the selected ID instead.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Nov 2012 03:17
To delete items, simply remove it from the array. First you should check if it has any child nodes. If it does, either prevent the deletion or delete the children with it.

Obviously, if you remove an element from the middle of the array, everything shifts down and suddenly the indices become meaningless. So we'll refactor the array manually before removing the element.

I believe this should work, however I have not tested it. Of the two functions the only one you need to call is removeMenuItem().



"You're not going crazy. You're going sane in a crazy world!" ~Tick
Duffer
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 11th Nov 2012 17:04
@ Phaelax & Mr909,

Hope you both follow this. My solution is, I hope, simple. Put the path of the node (ie. items/weapons/swords/claymore) in the name of each node in an array and, voila, you can sort or reverse sort.

Also, you can easily parse the nodes to delete all children and grandchildren nodes etc and everything else holds it's structure - the structure is in the name of the nodes (with path) themselves...

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...

Login to post a reply

Server time is: 2024-04-18 02:41:15
Your offset time is: 2024-04-18 02:41:15