Ok so I currently have my camera object doing 2 things, the very first logic block sets the “Overlay” scene to be an overlay I also tick the priority button so it’ll be sure to do it first. The second thing is run a script, The import part of the script for this issue is the first thing I do it create an instance of my “Client” class, when I do this the client creates an instance of my “Chat” class, inside the Chat class I’m trying to get 2 objects from my Overlay scene which are both text fields.
So I figured I’d test this using something like this…
listScene = logic.getSceneList()
for cur in listScene:
print(cur.name)
The issue is it will not list the Overlay scene when I do this in the Chat class constructor but if I run it a few times in the main loop it does end up finding the Overlay scene. Is there a known fix for this?
Edit: I suppose I could completely remove the chat from the client class and run it from the Overlay but the client has quite a bit of useful info to make it easier to work it and less need to rewrite the same code
Note This function [addScene] is not effective immediately, the scene is queued and added on the next logic cycle where it will be available from getSceneList
Based on what you said, it sounds like you could refactor the classes. Create a class or module that both the chat and the client class can subclass or import to avoid duplication.
Probably right about the classes but it’s a very small class really and I just did it the most simple way I could think of. I guess it’s possible to run chat.updateChat() as a module inside the overlay scene and run my clients recviece and send in the main scene.
Edit: I figured out a easy way to fix this so I figured I’d post it for anyone else who may have the same issue.
This is my Chat object’s update function so it is called every tick so it will update the scene object to the right one.
if not self.scene.name == "Overlay":
for cur in self.listScene:
if cur.name == "Overlay":
self.scene = cur
self.messageText = self.scene.objects["MessageText"]
self.inputText = self.scene.objects["InputText"]
print(self.scene.name)
self.listScene = logic.getSceneList()
else:
.............
The scene variable is set to a types.KX_Scene so it’ll have a null name to start I assume.
Why do you have a chat outside the overview scene?
If the overview scene should act as view to the chat (which resides somewhere else) the chat has to deal with missing view anyway. A good way is that the (objects of the) overview scene registers themselves at the chat as view. This would allow to even switch the overview scene if it is necessary.
I just use the Overlay because it seems like the right thing, the overlay will control all the menu’s, health and mana bar, inventory, chat, anything that is in a set position and in a 2D view. The game world and the game itself will run in the main scene.
I don’t understand exactly what you mean so I’m a bit lost as to why using a overlay isn’t the best option for this?
It could be put in there I’d just need to change around my client class is going to handle all my networking stuff and since most of the chat is just send and recvieve I made the chat class and actually create it’s instance with my client class. I guess if the client class just sent data to my overlay scene object to update the visual it would work fine too and perhaps be a better idea to keep the network code separate from the graphics. but it would still require accessing the overlay from the main scene. This may change your thoughts on it as I forgot to mention it’s a network based chat, not sure.
I do have it working perfectly now but I’m always open to better ideas. I will try to work on adding the graphical updates to the overlay scene but is there a better way to get the data from the Client class? It’s run from the main scene.