3

I want to create a FSM diagram and wanted to use plantuml for that. I stuck with backward arrows
There is a way to create backward arrows but it looks overcomplicated and too limited for such a simple task

@startuml
:start;
repeat :Ask to enter login;
repeat while(Is name valid?) is (No) not (Yes)
:play game;
@enduml

which gives this
enter image description here

but when you want to implement a little bit more complex logic like:

  1. Ask to enter name
  2. Ask to enter password
  3. On the third failed attempt go back to the (1)

it looks like it's just not possible with plantuml

I don't know if it called State diagram but I took a look on all types of diagrams plantuml supports and it seems to be the fittest one

IC_
  • 1,624
  • 1
  • 23
  • 57

2 Answers2

1

I would say that an activity diagram works best.

What you described is easy to explain, but complex to display in correct UML, I don't think that's specific to plantuml. Here's how I would express what you said:

PlantUML Activity Diagram

@startuml
start
while (App) is (running)
  :enter username;
  repeat
    :enter password;
    if (Password correct?) then (yes)
      :Play game;
      stop
    endif
  repeat while (Third attempt?) is (no) not (yes)
endwhile (exit)
stop
@enduml
jeffrey.d.m
  • 616
  • 8
  • 23
  • Can you make a additional sub-branch `play game -> AFK too long -> enter password`? – IC_ Aug 03 '21 at 07:02
0

As Jeffrey pointed out, you are more likely thinking in terms of activity diagram, your nodes being the actions that happen and not the states.

If you want a state diagram, you need to shift your mind to the background of your currently identified actions. So in the simplest means, there are two main states in your system:

enter image description here

Let's zoom into the first state, which appears to be more complex and deserve some substates. You have identified an Enter a name action while in the game configuration state. Until this action is completed, the name is not known. Once it is completed, the name will be known, but a validity check needs to be performed. You could express this with the following states:

enter image description here

You'll see that when entering the substate No valid name known, the first things that happens is to ask the name. And once everything is fine, you've finished the sub-state machine and can continue to the new states.

The plantuml code is:

@startuml
state Configuring {
  state NameNotKnown as "No valid name known":entry / Ask name
  state NameKnown as "Name knwon"
  [*] --> NameNotKnown
  NameNotKnown --> NameKnown : Name entered
  NameKnown --> [*] : Name is valid
  NameKnown --> NameNotKnown: Name is invalid 
}
[*] --> Configuring 
Configuring --> Playing : Launch game
Playing --> [*] : Game over
@enduml  

It's worth to mention that you could fine tune this diagram, using entry, exit and do behaviors in each simple state. Moreover, you could simplify my example using guarded transitions, and even behaviours that are expressed at transition level.

Christophe
  • 68,716
  • 7
  • 72
  • 138