Proper structure

BlitzMax Forums/BlitzMax Programming/Proper structure

Naughty Alien(Posted 2009) [#1]
..hi guys..im sort of new to Bmax (have it some time), and im getting to be step by step familiar with it..however, Im experiencing some 'problems' with structure i wanna build...actually, I did it and it works , but its 'looking' ugly since i still end up with sort of mixed OO and procedural way of doing it what i dont like and i wanna really get it all on proper OO way..so here it is..structure should look like as it is on shown pic..its representing skeleton of my behaviour structure for characters, so i just set it up at level loading and in runtime its updating on its own..so, each behaviour should trigger next behaviour in chain once it reach given condition true, and disable itself from update. So in main loop will be executed only one with flag true, and each behaviour should have self condition for enable disable. So it is always executed first loaded(set) behaviour then second after first trigger it, then third after second trigger it and so on, long as upon loading it has flag for execution enables (so it means at same time it may be situation that 2 or 3 or any number of behaviours may be executed at once..but point is that once they are trigered they will change state of the next one to them)..each behaviour should also have optional flag for deleting from Logic structure, once its executed and triggered next one in chain..so, for example, I would like to have such structure before main loop /setting it up/
'NPC1 set
Player1.Behaviour.Patrol(eventual parameters here for setting it up )
Player1.Behaviour.Talk_To(eventual parameters)
Player2.Behaviour.Go_To(target or anything else)

'NPC2 set
Player2.Behaviour.Idle(eventual parameters )
Player2.Behaviour.Dance(eventual parameters)
Player2.Behaviour.jump(eventual parameters)

so after everything is loaded , in main loop will be simply Update call and everything will be executed one by one, depending how triggering each other..

How should look like such structure??




Chris(Posted 2009) [#2]
Are you the same Naughty Alien using leadwerks?

If so in a few days I going to be posting a load of statemachine code which might be of use to you.


Naughty Alien(Posted 2009) [#3]
..yes its me..i have done this thing but i hate it because of procedural parts i did so its not all nice and properly structured..can you give me more details about statemachine code you refering to...a bit more description about its features, if you dont mind?


Jesse(Posted 2009) [#4]
I may not be a good candidate to explain this as I am still going through the process of learning how to structure myself. As a basic example look at the pocket asteroids game by James brown here:
http://www.blitzmax.com/Community/posts.php?topic=84272
he structured it in a way that made adding and adopting code simple and efficient.
I don't know how good it really is but it gave me a good idea on how to structure my code.
I also read a good post by AlexO a while back in this thread:
http://www.blitzmax.com/Community/posts.php?topic=81626#919932
I have not implemented as I have to adopt to this method and as you know, all habits are hard to break.


Chris(Posted 2009) [#5]
It's simlair to what you mentioned/wanted in the top post.

I'll be posting all my code on the leadwerks forum in a few days/week.

It will have a NPC statemachine in. States as objects.
Idle, attack, die, walk to attack etc.

Pathfinding.
Navmesh.

It's still all WIP but you might find it useful, can't hurt as it's all free..


Naughty Alien(Posted 2009) [#6]
..I see..thanks Chris...do you mind to eventually email me when you are done with it and ready to release, im really interested to see it/implement it , but im not much checking forums recently because im really busy with loads of things regarding my game (tuning up all animations/converting them in to one timeline sequence/cutscene creation)..im sorry if im bothering you but Ill really appreciate small notice about it..I hope you will comment code so I can eventually add stuff I need(states)...thanks a lot..with your stuff and modified Gillisie's animation system i modified for my cutscene management, my framework will be pretty much done..


Naughty Alien(Posted 2009) [#7]
@Jesse
Thanks buddy..you are right...old habbits are really a problem but im slowly getting rid of it..how much I loved B3D , now I dont like since habbits of forming structure there causing some difficulties when you wanna tune up things purely on OO..but im almost there..


JoshK(Posted 2009) [#8]
I usually just do something like this:

TAI

Field state:int

Method Update()
Select state
Case AISTATE_SLEEP
'Do stuff
Case AISTATE_EAT
'Do stuff
If IsSleepy()
state=AISTATE_SLEEP
Return
Endif
Case AISTATE_GOTOTHESTORE
'Do stuff
EndSelect
EndMethod