Skip to content

Commit df5e636

Browse files
committed
gle: Fix table variable errors.
1 parent 002a561 commit df5e636

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Editor/Inspectors/VisualScriptingGamelogicEngineInspector.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public override void OnInspectorGUI()
6666
}
6767

6868
EditorGUILayout.TextField("Table Variables", new GUIStyle(EditorStyles.boldLabel));
69-
PrintState(_gle.TableState);
69+
PrintState(_gle.TableState, _gle.TableVariableDefinitions);
7070

7171
if (_gle.PlayerStates.Count == 0) {
7272
EditorGUILayout.HelpBox("No player states created.", MessageType.Info);
@@ -80,21 +80,21 @@ public override void OnInspectorGUI()
8080
}
8181
if (_playerVarFoldout[playerId] = EditorGUILayout.BeginFoldoutHeaderGroup(_playerVarFoldout[playerId], $"Player {playerId}")) {
8282
EditorGUI.indentLevel++;
83-
PrintState(_gle.PlayerStates[playerId]);
83+
84+
if (_gle.CurrentPlayerState == _gle.PlayerStates[playerId]) {
85+
EditorGUILayout.HelpBox("Current Player", MessageType.Info);
86+
}
87+
88+
PrintState(_gle.PlayerStates[playerId], _gle.PlayerVariableDefinitions);
8489
EditorGUI.indentLevel--;
8590
}
8691
EditorGUILayout.EndFoldoutHeaderGroup();
8792
}
8893
}
8994

90-
private void PrintState(State state)
95+
private static void PrintState(State state, IEnumerable<VariableDefinition> definitions)
9196
{
92-
93-
if (_gle.CurrentPlayerState == state) {
94-
EditorGUILayout.HelpBox("Current Player", MessageType.Info);
95-
}
96-
97-
foreach (var varDef in _gle.PlayerVariableDefinitions) {
97+
foreach (var varDef in definitions) {
9898
EditorGUILayout.LabelField(varDef.Name, state.Get(varDef.Id).ToString());
9999
}
100100
}

Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
118118
_player = player;
119119
BallManager = ballManager;
120120

121+
// create table variables
122+
foreach (var propertyDefinition in TableVariableDefinitions) {
123+
TableState.AddProperty(propertyDefinition.Instantiate());
124+
}
121125
OnStarted?.Invoke(this, EventArgs.Empty);
122126
EventBus.Trigger(VisualScriptingEventNames.GleStartedEvent, EventArgs.Empty);
123127
}

0 commit comments

Comments
 (0)