I’m trying to create a turn based system. Because of the nature of the system, the player needs to be able to switch back and forth between characters that they control and make decisions for them.
Currently, I’m working on the control-switching mechanism, but I’m being told that I can’t have cyclic tables, although I’m not sure where mine is coming from.
I’ll don’t want to just dump all my code on here so I’ll try and keep my explanation concise:
To collect player inputs, I create GUI for each character which allows them to select a skill. I need information about the state of the battle, such as who is on each side and their stats etc. which is held in a Battle object which also creates the GUIs and places them in the correct players. In the GUI is a modulescript which is responsible for holding information that GUI needs, such as enemies and allies, and the skills that the character has.
The GUI is created at the start of a round, and because people can perform actions throughout the round, I constantly need an updated edition of the ‘Battle’ object to draw information from in the GUI’s modulescript. So in the modulescript I created a Remote Function which requests information from the Battle object:
in modulescript
skillsHolder.getBattleState = function()
print("called")
return script.getBattleStateFromObject:InvokeServer()
end
in Battle object
for i, remote in ipairs(getBattleStateRemotes) do
remote.OnServerInvoke = function()
print("INVOKED")
return self
end
end
Also, “called” and “INVOKED” print normally, but if I try to deep copy the Battle object, the script breaks. I think it gets called thousands of times but I have no idea why since even in this case, “called” and “INVOKED” seem to only print once per invocation.
The error is from this line in the module script
return script.getBattleStateFromObject:InvokeServer()
and occurs whenever I try to perform any action (attacking or switching characters) after already doing it once. I’m really lost on why this is the case because nothing notable changes after attacking, and I know that without more context it might be hard to find the issue but I was wondering if from this information (which I think is the most relevant) there is something obvious that I’m doing that is problematic. Any advice would be appreciated