DGS OOP Class: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 15: Line 15:
*'''Any variable of the table are get/set via [[dgsSetProperty]]/[[dgsGetProperty]] ( Exclude DGSElement )'''
*'''Any variable of the table are get/set via [[dgsSetProperty]]/[[dgsGetProperty]] ( Exclude DGSElement )'''


==Start==
==Get Started==
Instead of using  
Instead of using  
<syntaxhighlight language="lua">
<syntaxhighlight language="lua">

Revision as of 07:38, 15 November 2018

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,
	...
}

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