(Beginner) 9. Classes
Login
-
Join
Home
Games
Game Engine
Resources
Tutorials
Description:
Show how to create and use a class in Lua.
Author:
LastEnd
Topic:
Scripting
Last Tutorial:
(Beginner) 8. Inline Classes
Next Tutorial:
(Intermediate) 1. Timers
Script:
-- Game.vlua file Scripting_RegisterClass("engine") Scripting_RegisterClass("ui") Scripting_RegisterClass("Adding.lua") -- Do not edit this method. It is generated by the visual designer function InitializeComponent() dialog = UI.Dialog.Add("dialog", 0, 0, 1348, 705, true, -16777216, -16777216, -16777216, -16777216, 0, -987833, "", 0, false, true, true, false, true, "Arial", 24, false, false) lbl1 = UI.Label.Add("lbl1", dialog, [[Label]], 91, 37, 100, 22, 0, 0, "Segoe UI", 22, false, false, -1) lbl2 = UI.Label.Add("lbl2", dialog, [[Label]], 94, 106, 100, 22, 0, 0, "Segoe UI", 22, false, false, -1) Window_Resize() end--* -- Do not edit this method. It is generated by the visual designer function Window_Resize() local _width = Engine.GetWindowWidth() local _height = Engine.GetWindowHeight() UI.Dialog.SetSize(dialog, _width, _height) end--* InitializeComponent() a1 = AddingClass.create(10) a2 = AddingClass.create(100) UI.Label.SetText(dialog, lbl1, a1.DoIt(1)) UI.Label.SetText(dialog, lbl2, a2.DoIt(42)) -- Adding.lua AddingClass = {} function AddingClass.create(baseNum) local class = {} local name = "Adding" local baseNumber = baseNum setmetatable(class, AddingClass) function class.DoIt(num2) return baseNumber + num2 end return class end
ALL COMMENTS (
0
)
You need to
LOGIN
or
SIGN UP
before you can post comments.
Policy
-
Support
-
Contact
-
Terms of Service
-
Lost Serial
-
Site Map
-
Feedback