DGS OOP Class

From Multi Theft Auto: Wiki
Revision as of 07:41, 15 November 2018 by Thisdp (talk | contribs) (→‎Get Started)
Jump to navigation Jump to search

DGS provides not only POP ( Procedure Oriented Programming ) but also OOP ( Object Oriented Programming ). This page introduces OOP of dgs.

Structure

When using DGS OOP, DGS objects being operated are no longer elements, instead, they will be tables ( table is the only type whose call methods can be defined in lua ) . Here is the structure of DGS OOP Object:

DGSDxObject = {
	DGSElement = DGSElement -- The actual dgs element
	function1,
	function2,
	...
}
  • The built-in functions are non-modifiable
  • Any variable of the table are get/set via dgsSetProperty/dgsGetProperty ( Exclude DGSElement )
  • After importing DGS OOP Class, there is a table called : DGSClass

Get Started

Instead of using

 label = exports.dgs:dgsCreateLabel(0, 0, 0.5, 0.1, "text", true)
 DGS = exports.dgs
 label = DGS:dgsCreateLabel(0,0,0.5,0.1,"text",true)
 loadstring(exports.dgs:dgsImportFunction())()-- load functions
 label = dgsCreateLabel(0,0,0.5,0.1,"text",true) --create a label

We provides Object Oriented Programming

 loadstring(exports.dgs:dgsImportOOPClass())()-- load OOP class
 window = DGSClass:createWindow(0,0,0.5,0.1,"test",true) --create a window with oop
 label = window:createLabel(0,0,1,1,"label",true) --create a label inside the window
 label.text = "DGS OOP Test" --set text

Functions