Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: idlehanzgray on October 25, 2022, 03:29:23 am

Title: State Machine - Choice help
Post by: idlehanzgray on October 25, 2022, 03:29:23 am
Greetings all - I've been learning about state machines and attempting to follow along on the various tutorial videos and RTFM. However, I've come across a problem with the use of the choice element in a simple state machine that I created (I wanted to create my own simple example to demo how it works).

This is my state machine

Initial
QueueingForIceCream
Deciding
Choice
Two triggers from Choice are:
Depending on the 0/1 the following states are:
Vanilla - increment weight by 1
Chocolate - increment weight by 1
there is a junction which returns to the Deciding state

My challenge - the state machine works - but - when it gets to Choice - it just sits there. Even though I can check the value of this.iceCreamFlavor and see whether it is a 0 or 1 one - but the states sit in the waiting triggers queue and I have to double-click one of them to get it to fire. I want it to just run automagically.

What am I missing?

(https://imgur.com/a/TY2q95Y)
Link to image of state machine here: https://imgur.com/a/TY2q95Y (https://imgur.com/a/TY2q95Y)
Title: Re: State Machine - Choice help
Post by: Eve on October 25, 2022, 08:00:23 am
It look like those aren't in the guard for the transitions. (They aren't between '[' and ']')

I suspect you'll also have a problem because it looks like you've put an assignment instead of equality check in that condition. (Javascript syntax)

Finally, I think none of the guards should have a semi-colon.
Title: Re: State Machine - Choice help
Post by: idlehanzgray on October 25, 2022, 08:04:22 am
Thanks for the response. I've been playing with different options - one of which is using the javascript in the guard - but it had the same result. I'll redo with the guard and report the image.
Title: Re: State Machine - Choice help
Post by: idlehanzgray on October 25, 2022, 08:14:32 am
Here's the link to the new image. The triggers are named Vanilla and Chocolate, respectively - and now the guards are once again populated with the JavaScript. I've expanded the capture so that the values of the variables can be seen - and the event window showing the two waiting triggers.

https://imgur.com/FQ5bNpn (https://imgur.com/FQ5bNpn)
Title: Re: State Machine - Choice help
Post by: Eve on October 25, 2022, 08:38:59 am
Two of the problems I highlighted are still there, but you've added another one.

Title: Re: State Machine - Choice help
Post by: idlehanzgray on October 26, 2022, 12:36:37 am
Thank you! That assignment operator was indeed tripping me up. If I had a nickel for every time I used = when I needed to use == in my life well... I'd have a lot of nickels.

The state machine now works as intended. I've posted an updated image in the link below for anyone else following along that may have similar challenges.

https://imgur.com/SMYgX4e (https://imgur.com/SMYgX4e)