+1 vote

Hi, just starting out, and I'm trying to figure out how to structure my nodes/scripts/scenes logically... Basically, I'm trying to make a game using a split screen (two viewports), which will be highly interactive. Left will have a world with player & entities, and the right a sort of 'action' board which will be highly dependent on everything happening on the left side...

My issue is that when I'm trying to initialize the action board, then I need a bunch of stuff; player characters, stats, items, enemies, enemy stats, enemy items, world state (ex; location forest, road, city, etc.), etc. So there's just way too many things to pass to initialization methods...

And yeah this just doesn't seem to fit very well with the nodes/scene structure... Well... It just popped in my mind that I could just pass my entire Master Node to the action board and so could have access to everything!

Right now I have:
|--- ViewPort for [MasterWorld Scene]
|--- ViewPort for [ActionBoard Scene]

MasterWorld Scene/node
|-- World

ActionBoard Scene/node
|-- Board1
|-- Board2

Hmmm... So yeah now this seems kind of obvious... Pass the entire MasterWorld node to the ActionBoard, and make the MasterWorld script a sort of getter & function caller for all its sub elements for the Board Script? The 'world' will also influence the board, so... It will also need to call some functions. It'll also need to make changes; player HP, location, call player attack, kill enemy, etc., So basically... Just pass the entire Board to the World, and the World to the Board? Or is there some better or more practical way of doing things?


in Engine by (131 points)

1 Answer

+2 votes
Best answer

Yes you could do it that way. But you don't need setter/getter. You can access each var simply by:

var wanted_node = $Path/To/Node

If you're looking for something like global variables have a look into Singletons:

I'm not a pro myself, so these are just ideas :)

by (52 points)
selected by

To improve answer style in general you should replace all _ with \_ which will make an actual _ appear or write function names inside code. It's better to read. Thanks for helping this Q&A.

Thanks for the answer, and thank you, Jowan-Spooner, for your suggestion.

Yeah the issue though with going with the Node structure is that if the Node structure changes, your code breaks down and you need to go back and correct every impacted script... With a "getter Node Script", you only need to correct that one script since other Nodes only refer to that one to obtain whatever info it needs. Seems better to me, but who knows...

The AutoLoad does seem quite interesting, but I'm not sure I quite grasp the concept so far... The interactions go both ways, Board influences World and World influences Board, so if both the World and the Board need to be AutoLoaded, then everything is AutoLoaded...

And like I said, there's going to be hundreds of potentials enemies, which are required for the board, so AutoLoading them seems to make little sense... Woa anyway not very simple coming from object oriented background... Thanks!

Thanks, I edited it :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.