Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


6.3 class changes

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Thu Jun 13, 2013 4:11 pm    Post subject: 6.3 class changes Reply with quote

If you've downloaded 6.3 and are looking at main.lua you may notice that a lot of the old class related functions have been changed.

Instead of form_hide(form) and form_show(form) it now just show() and hide() , and the same for a lot of other function

Let's take a look at the CEForm and Form class:
Code:

Form Class: (Inheritance: ScrollingWinControl->CustomControl->WinControl->Control->Component->Object)
properties
  OnClose: function - The function to call when the form gets closed
  Menu: MainMenu - The main menu of the form

methods
  centerScreen(); : Places the form at the center of the screen
  hide() : Hide the form
  show() : show the form
  close():  Closes the form. Without an onClose this will be the same as hide
  showModal() : show the form and wait for it to close and get the close result
  isForegroundWindow(): returns true if the specified form has focus
  setOnClose(function)  : function (sender) : Return a CloseAction to determine how to close the window
  getOnClose() : Returns the function
  getMenu() : Returns the mainmenu object of this form
  setMenu(mainmenu)

  setBorderStyle( borderstyle):  Sets the borderstyle of the window
  getBorderStyle()

  printToRasterImage(rasterimage): Draws the contents of the form to a rasterimage class object
  dragNow():  Call this on mousedown on any object if you wish that the mousemove will drag the whole form arround. Useful for borderless windows (Dragging will stop when the mouse button is released)

CEForm Class: (Inheritance: Form->ScrollingWinControl->CustomControl->WinControl->Control->Component->Object)
createForm(visible OPT): creates a CEForm class object(window) and returns the pointer for it. Visible is default true but can be changed
createFormFromFile(filename): Returns the generated CEform

properties
  DoNotSaveInTable: boolean - Set this if you do not wish to save the forms in the table
methods
  saveToFile(filename): Saves a userdefined form
  getDoNotSaveInTable(): Returns the DoNotSaveInTable property
  setDoNotSaveInTable(boolean): Sets the DoNotSaveInTable property

As you can see, objects have properties and methods (and of course, inheritance)

Now, if you call createForm() you will get an object of the CEForm class.
Code:

myform=createForm(true)


To access the DoNotSaveInTable property you can use this: (Note the use of . instead of the old ceform_getDoNotSaveInTable(myform) )
Code:

  oldState=myform.getDoNotSaveInTable()
  myform.setDoNotSaveInTable(not oldState)


But since the property DoNotSaveInTable is published, this means you can also directly change it without having to call the methods manually:
Code:

  myform.DoNotSaveInTable=not myform.DoNotSaveInTable

Which is probably a more cleaner looking code

Now for the inheritance. As before, you can still use the functions of objects that the current object is inherited from.
In the past, you would do form_show(myform) but now:
Code:

  myform.show()


Same for accessing the properties that the parents of the object provide
Code:

  myform.Top=100

In this case, Top is actually a property of the Control class, which Form also inherits from, so it can use that property as well.

Also, not all properties are explicitly published to lua, but you CAN make use of them as long as they are published. (visible in the form designer)
Let's take for example the AlphaBlend value of the form.
Code:

myform.AlphaBlend=true
myform.AlphaBlendValue=127

Note that for some properties you sometimes might have to use a string as input instead of a number. (Or in some cases when you get a charcase wrong, it used the lookup method instead of the predefined method)

One more thing that might need some explaining. In the previous version you had to use setMethodProperty to set the event handler to a specific function
In this version you can just use propertyname=function
e.g:
Code:

function someoneWantsToCloseMyForm(sender)
  print("bye")
  return caHide
end

myform.onClose=someoneWantsToCloseMyForm


but also:
Code:

myform.onClose=function(sender)
  print("the end")
  return caHide
end

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping


Last edited by Dark Byte on Sun Jun 16, 2013 2:03 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Jun 13, 2013 5:21 pm    Post subject: Reply with quote

Another thing worth to mention, we can use constructions like this:
Code:
menuItem = getMainForm().getMenu().getItems()


Or:
Code:
pic=createPicture()
font = createFont()
(...)
pic.Bitmap.Width=128
pic.Bitmap.Height=64
pic.Bitmap.Canvas.Font.assign(font)
pic.Bitmap.Canvas.Brush.Color=0x0000FF  -- red color

_________________


Last edited by mgr.inz.Player on Thu Jun 13, 2013 6:08 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Thu Jun 13, 2013 5:31 pm    Post subject: Reply with quote

also
Code:

menuItem=getMainForm().Menu.Items


and you can even go further:
Code:

getMainForm().Menu.Items[0].Caption="Better &File Menu";

or
Code:

Items=getMainForm().Menu.Items;
Items[7].Caption="WTF?";
Items[7].Item[0].Caption="I do not need this"
Items[7][3].Caption="Peeps!"

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Jun 13, 2013 8:09 pm    Post subject: Reply with quote

Still, creating menu is troublesome Very Happy

We can make it easier, like this:

Click Table->click Create form->close Form Designer
then execute this script:
Code:
function createOrGetBaseMenuItem(form)
  if form==nil then return nil end

  local baseItem = nil
  if not form.Menu then baseItem = createMainMenu(form).Items
  else                  baseItem = form.Menu.Items end

  return baseItem
end

function addMemuItem(parent,caption)
  if parent==nil then return nil end

  local newItem = createMenuItem(parent); parent.add(newItem)
  newItem.Caption = caption

  return newItem
end

baseMenuItem = createOrGetBaseMenuItem(UDF1)
File = addMemuItem(baseMenuItem,'File')
Edit = addMemuItem(baseMenuItem,'Edit')
View = addMemuItem(baseMenuItem,'View')

Open = addMemuItem(File,'Open file')
Save = addMemuItem(File,'Save file')

Undo      = addMemuItem(Edit,'Undo operation')
SelectAll = addMemuItem(Edit,'Select all')



But, I get crash error after closing CE when UDF1 is visible. If I hide UDF1 window and then close CE, there's no crash.

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites