How to structure nodes logically as to pass an ensemble of items to a component?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nwgdusr999

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?


:bust_in_silhouette: Reply From: PrincessClumsy

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 :slight_smile:

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.

Jowan-Spooner | 2019-05-21 21:04

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

Ertain | 2019-05-21 23:37

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!

nwgdusr999 | 2019-05-22 12:07

Thanks, I edited it :slight_smile:

PrincessClumsy | 2019-05-22 14:10