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 / Managing Internal Player States

Author
Message
anwserman
15
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 9th Aug 2011 13:23 Edited at: 9th Aug 2011 13:31
This has been a problem that I've dreaded tackling, since everytime I do it, it always turns into a mess or some sort of spaghetti code. Basically, I don't know how to write a good character controller that I can extend.

If I start writing something, it'll typically break whenever I need to add a feature. But I'm trying to plan ahead now, but all I'm getting is fear of this code and a headache.

I've came up with the basic rules the player character needs to abide by. "Shift" rules modify the current state by some degree, whether be limiting features, modifying the playback animation, or both.



What would be the best way to implement a internal player state controller? I'm just looking at this overall and am overwhelmed. Any suggestions? Anyone else have any clever solutions or ideas for their character controllers?

Hi there. My name is Dug. I have just met you, and I love you.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Aug 2011 14:20 Edited at: 9th Aug 2011 14:22
I tend to have a set of states just like this (for animation purposes at least).

I use constants for my player state IE:


I can set my player state like this:


...then I can run animations based on this:


Just written on the fly as an example, may contain nuts...

anwserman
15
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 11th Aug 2011 14:30
Ah, a simple example of a Finite State Machine =)
I researched it a bit, and that's basically what it is!

Thank you for the assistance.

Hi there. My name is Dug. I have just met you, and I love you.
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Aug 2011 16:06
anwserman, that code isn't a state machine, there is no code to change the states within the select routine. A state machine may be exactly what you need though, once you get your head around how they work. For now, I'd stick with the code baxslash has to get to working before you go more complex.

Baxslash I realise your code is just an example but you may like to know about one of IanM's commands that simplify it somewhat...

Value = WRAP( Current Value, Min Value, Max Value)

This code does all your frame wrapping for you

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Aug 2011 16:13
Quote: "This code does all your frame wrapping for you"

Yes I know that one thanks Batvink! I just find it easier to use native commands as much as possible on the forums as I get sick of saying "What do you mean you don't have it? Get the Matrix Utility plugin NOW!!"

I actually wrote a C# version of the wrap command with the same overloads at work because I couldn't easily find the equivalent... and for a bit of a diversion

mr_d
DBPro Tool Maker
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 11th Aug 2011 16:57 Edited at: 11th Aug 2011 16:58
@baxslash
Also, because it seems we are picking on baxslash a little anyway
since you have already defined the constants, you can reuse them and get rid of the extra rem statements:



baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Aug 2011 17:06
Quote: "Also, because it seems we are picking on baxslash a little anyway"

Nobody's picking on me, they wouldn't risk the backlash. Anyway, my version is a little more obvious in terms of how the commands work (I think). It's not how I would necessarily code it in my own project.

Quote: "Ah, a simple example of a Finite State Machine =)
I researched it a bit, and that's basically what it is!"

Never heard it called that before but I do tend to think in terms of State or Mode when it comes to these kind of systems.

Login to post a reply

Server time is: 2026-07-10 15:31:04
Your offset time is: 2026-07-10 15:31:04