GUI Scripting Structure

Hello, i would like to know your approach and the patterns that you follow to script your UI elements and to add custom UI elements, perhabs using OOP, And what’s the reasons that made you follow it.

Thanks!

I like using a table that I iterate over to give connections to the functions and due to the possible messy amount of Tweens you might want to use you’d order it in a clean way that tables can sometimes help with.

If you’re barely scripting the GUI then a normal approach works fine to me like maybe just 1-2 buttons.

2 Likes

Yes i used that method in my last plugin. it wasn’t the best approach but it did the work needed, thanks for sharing!

I won’t go into detail about it but I find using a model-view-controller type architecture as a great way to organise my code when working with GUIs.

1 Like

Looks interesting! can you explain what it is and why you choosed it? or at least link to it?

A very basic summary; I’m no expert so my explanation may not be 100% correct.

image

The diagrams on google all have different ways of visualising this architecture so the image above is just to give you a general idea of how this works.

  • Model
    • Stores information relevant to the user interface such as a player’s coins or experience
  • View
    • Your GUI instances are part of the view
    • The view also contains methods used to update the GUIs based on values in the model
  • Controller
    • Listens to events and calls methods from the model and view accordingly
    • Bridges the gap between the model and the view. It basically calls all the shots

I chose to use this as my framework for GUIs because prior to learning about this, my code was an organisational disaster. I’m talking scripts scattered between different GUIs and really bad spaghetti code. Using this new method, however, I can easily organise my functions so that reading and debugging my code is a lot smoother. I just needed some sort structure to my code, really.

From what I’ve been taught is that MVC design patterns are commonly used within the industry, though I can’t speak from experience. Quickly googling “mvc” will lend you plenty of resources to read further into this concept. In fact, I’ve been considering writing up a tutorial on this practice and how to implement it within Roblox, though I’m not sure how useful it would be to viewers.

5 Likes

That’s a great structure! while i can implement it myself, but i would like to see your way of doing it like in a tutorial. Thanks!