Jump to content

Recommended Posts

Hi,

I'd like to write some Ais behaviors and it seems to me that they are usually done with FSM files. I didn't read so much things about that. I'd like to know what differences, gain or advantages makes FSM scripting vs SQF.  Then, the way to integrate a FSM file in some working environment (init.sqf call?) Thanks.

  • Like 1

Share this post


Link to post
Share on other sites

What I can tell is that using FSM for AI behaviour is much more easier to read than a sqf file. This is because of its schematic view.
If I am at desktop I ll post a YouTube video from which I learned using FSM...

sent from mobile using Tapatalk

  • Like 3

Share this post


Link to post
Share on other sites

video...

 to answer ur wuestion bout FSM integration. You can do it like with any other script (sqf). U can use an FSM to just be used in a certain situation maybe executed by a trigger and u can use it all the time. as I said it can used the same way as any other scripts.

You execute an FSM with this:

execFSM

 

  • Like 1

Share this post


Link to post
Share on other sites

FSMs are great for readability in the first place, as stated by @sarogahtyp.

Where FSMs really shine is doing complex stuff, first and foremost branching out to different states with the possibility of every state being able to lead to any other state and having priorities in which state to branch out on top of that.

When I'm bored I goof around with this:

j6UMKSw.jpg

 

It's a basic AI fsm that dynamically adjusts to threats/threats to other groups from same side within range and calls reinforcements if needed/allowed.

Now while doing something like this in sqf is entirely possible, expanding this with other branches could be incredibly complicated to do in sqf.

The visual representation in FSM editor really helps.

 

There's no notable difference between FSM and sqf regarding performance, as far as I know.

 

Cheers

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Wow, thanks guys for these explanations. I just have to jump into it!

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

Wow, thanks guys for these explanations. I just have to jump into it!

Definitely yes. Once you installed the FSM editor you need to make a template file so you don't have to compile it with the cfg everytime you make a new fsm.

Here's my empty fsm template to save you some trouble.

Have at it!

 

Cheers

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

FSM benefits:

 

- readability: good for multi-person projects who need to understand each others work

 

FSM costs:

 

- unscheduled environment only: cant make use of thread suspensions/sleep to manage performance

  • Like 2

Share this post


Link to post
Share on other sites
5 hours ago, fn_Quiksilver said:

- unscheduled environment only: cant make use of thread suspensions/sleep to manage performance

What about spawning some code? It seems to me workable even on FSM code boxes.
But I see what you mean:  there is no sleep or waitUntil boxes, just the possibility to play with diag_tickTime and some counter in a condition box. Right?

 

Btw, I tried to disable "FSM" on a unit prior to run some test code... I was just trying something "basic" as AI driving by night with lights on.

That failed at most. the disableAI "FSM" keeps its mystery and the arma engine override all attempts of my FSM, each time the AI behavior shifts to "combat".

On the other hand, I discovered that a simple disableAI "autocombat" is perfect for that.

Share this post


Link to post
Share on other sites

Well this is something i'm asking myself since quite a while but so far i could not find a 100% accurate answer to this question...

 

To my understanding executing functions in unScheduled environment is better because they will be executed / read and return their value much faster.

But somehow executing functions in unScheduled environment depending on how busy the script engine is may lead to critical freeze or/and FPS drops.

 

For example:

I use a .sqf script with a while { (True) } do loop which is used by each A.I. group in a mission with a sleep 5 delay and some not too expensive functions in it executed every 5 secounds.

The .sqf script will be in scheduled environment which means it can be delayed / moved in the script engine queue to free up resources for other more important code.

 

If i convert this .sqf script to F.S.M. it will be in unScheduled environment.

 

If i use 50 - 70+ A.I. groups in a mission all running the unScheduled F.S.M. will it be a bad idea to do so or would it be better to use the .sqf instead?

 

I don't really use F.S.M. because of the diagram design i mainly use F.S.M. to switch from scheduled to unScheduled environment.

 

To me somehow it feels like .sqf would be better for this task but just as said i can't really tell for sure... :headscratch:

Share this post


Link to post
Share on other sites

Therefore IMHO scheduled is better always except the case, where accurate execution timing is essential. Also never liked FSMs - too used to do stuff in SQF, complex or not. 

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for your replay Rydygier. :icon5:

 

Damn i already feared this...

Instead of optimizing i did de-optimize by overloading the script engine with too much unScheduled code... Too bad... :icon1:

Well guess i learned something new... :thumbs-up:

Share this post


Link to post
Share on other sites

you got that wrong i believe

 

unscheduled: execute NOW no matter what and until finished - as result can lead to (short) freeze, and lower fps if abused way too much constantly (however other factors like entity creation (AI, vehicle, object, etc) and overall number of entities likely have way higher impact/relevance for fps - unless you use unscheduled wrong or are really bad in coding)

 

scheduled: run only during 3ms timeframe. the actual execution order each (execution) frame/cycle is determined by engine scheduler taking in multiple factors

 

unscheduled may not be necessary all the time, and can be more complex to set up, yet scheduled has no inherit benefit AFAIK

Share this post


Link to post
Share on other sites
3 hours ago, killzone_kid said:

FSM is scheduled

 

I'm no expert, but isn't it a little more complicated than that? FSM condition evaluation is on each frame and unscheduled. 

 

Do you mean that they somehow run on a 3ms schedule, but the code contained within the FSM is executed in an unscheduled environment? You are not allowed to use sleep/waituntil in an FSM.

Share this post


Link to post
Share on other sites
18 hours ago, .kju said:

unscheduled: execute NOW no matter what and until finish - as result can lead to (short freeze), and lower fps if abused way too much constantly (however other factors like entity creation and number likely have way higher impact/relevance for fps - unless you use unscheduled wrong or are really bad in coding)

Yes this is exactly what i belive to notice when switching from .sqf to .fsm each time i use the .fsm the mission will be kind of laggy for some milliseconds right after start.

Its just a really really short delay / freeze so i don't know if its just my imagination but somehow to me it feels like the engine has a much harder time reading and executing all the .fsm code even if its not too much compared to the same .sqf which does the job much more relaxed without any noticable impact.

 

17 hours ago, killzone_kid said:

FSM is scheduled

Oh it is?

Damn i was reading a lot of .fsm stuff during the last couple days and to me it all sounded like it is unScheduled... Well in this case R.I.P. unScheduled environment... :icon1:

This means in terms of code performance / speed there will be almost no different to normal .sqf scripts.

 

13 hours ago, genesis92x said:

 

I'm no expert, but isn't it a little more complicated than that? FSM condition evaluation is on each frame and unscheduled. 

 

Do you mean that they somehow run on a 3ms schedule, but the code contained within the FSM is executed in an unscheduled environment? You are not allowed to use sleep/waituntil in an FSM.

Welcome to the club genesis92x! :icon5:

 

Yeah this is exactly how i understand it right now... BUT i once more can be wrong...

I very often used .fsm over .sqf to initialize all my functiuons and stuff and to me it looked / felt like .fsm did the job much faster than .sqf maybe because of the faster condition evaluation?

 

I don't know... :headscratch:

Share this post


Link to post
Share on other sites

fsm conditions are checked per frame from what i recall (if the given fsm is checked this cycle by the scheduler)

the fsm execution i dont recall. nothing on the BIKI about this?

 

also keep in the mind the execution order: i think it was fsm->sqf->sqs but also better double check that

Share this post


Link to post
Share on other sites

Okay many thanks for your explanations guys! :thumbs-up:

Share this post


Link to post
Share on other sites

Thanks for explaining it, instead of just linking to the wiki! There isn't much documentation on it 🙂 

  • Like 1

Share this post


Link to post
Share on other sites
On 8/27/2019 at 2:55 PM, snkman said:

To my understanding executing functions in unScheduled environment is better because they will be executed / read and return their value much faster.

They are only a little faster, because they don't have to constantly check whether the 3ms scheduler limit is over.
what do you mean by "they will be executed/read" scheduled scripts are also executed and read.

 

On 8/27/2019 at 2:55 PM, snkman said:

But somehow executing functions in unScheduled environment depending on how busy the script engine is may lead to critical freeze or/and FPS drops.

No that has nothing to do with how busy the script engine is.
Unscheduled scripts freeze the game, nothing else runs until the script has finished.

Share this post


Link to post
Share on other sites
42 minutes ago, Dedmen said:

They are only a little faster, because they don't have to constantly check whether the 3ms scheduler limit is over.
what do you mean by "they will be executed/read" scheduled scripts are also executed and read.

Yes of course! :icon2:

 

But for example call vs spawn: ArmA Scripting Tutorials: Code Performance

 

42 minutes ago, Dedmen said:

No that has nothing to do with how busy the script engine is.
Unscheduled scripts freeze the game, nothing else runs until the script has finished.

Okay. :icon5:

I'm sorry i don't have the full picture of how exactly the engine works in detail...

In this kind of stuff i use a lot of guessing and assume how it could work... :icon1::headscratch:

 

But anyway thanks for your explanation Dedmen! :thumbs-up:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×