Jumping to procedure in another TUIState

How can I directly go to a procedure that is in another state?
Here both buttons in TStateMenu make StatePlay the active unit, but both should jump to different procedures within StatePlay. (ClickIntroduction should start an intro procedure in StatePlay).

procedure TStateMenu.ClickNewGame(Sender: TObject);
begin
  TUIState.Current := StatePlay;
end;

procedure TStateMenu.ClickIntroduction(Sender: TObject);
begin
  TUIState.Current := StatePlay;
end;

Overall, you shouldn’t “go to a procedure in another state”. Every state starts with Start when set as Current. You may set some parameters or call some procedure to set some parameters, but start sequence should always be the same.

To do so you can do something like:

procedure TStateMenu.ClickNewGame(Sender: TObject);
begin
  StatePlay.NewGame := true;
  TUIState.Current := StatePlay;
end;
1 Like

Yes, I already thought it was not the right way but I only needed it for the game menu state.
And thanks, I did not know yet I could directly access variables directly from StatePlay from within TStateMenu.