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 


Timer properties : Tag?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
sjl002
Master Cheater
Reputation: 0

Joined: 31 Aug 2013
Posts: 305

PostPosted: Tue Jun 14, 2016 8:23 am    Post subject: Timer properties : Tag? Reply with quote

Hi.
In timer properties ,Tag in what the lua scripts used?(Can you write an example for tag?)

Very Thanks
*SJL002*
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Jun 14, 2016 8:34 am    Post subject: Reply with quote

Almost all objects have a Tag property that can contain an integer
you can use that as an index into an array of objects you may with to use.

I often use createRef()/getRef() , but you could just as well create an custom table like mydata and use the Tag object as an index into that array ( mydata[Object.Tag] )


e.g at http://forum.cheatengine.org/viewtopic.php?p=5677212#5677212 I use createRef to add the Ultimap form to the registry table. (it returns an index into that table)
with getRef I am then able to get the ultimap Form at a later time. (Which I also pass on to the MenuItem object's Tag so that menu click can find the form as well)


Note that you can also encapsule multiple objects into one.
e.g:
data={}
data.form=myform
data.valuex=123
data.test="something"

createRef(data) will return a single integer which you can assign to the Tag property.
getRef can be used on that integer to get that data table

_________________
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
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Tue Jun 14, 2016 10:17 am    Post subject: Reply with quote

In that example, since the timer's OnTimer function and menu item's OnClick function are within the scope of the form f passed to the formAddNotification function, wouldn't it be fine to use that reference instead?
Code:
registerFormAddNotification(function(f)
  if f.ClassName=="TfrmUltimap" then
    --spawn a timer that runs as soon as the gui is responsive again
    local t=createTimer(nil)
    t.Interval=1
    t.OnTimer=function(t)

      --add a copy selection to clipboard menuitem
      f.ListView1.MultiSelect=true --enable multiselect

      local mi=createMenuItem(f.PopupMenu1)
      mi.Caption="Copy selection to clipboard"
      mi.OnClick=function(m)
        --code to copy to clipboard
        local i
        local lv=f.ListView1
        local sl=createStringlist()

        for i=0,lv.Items.Count-1 do
          if lv.Items[i].Selected then
            sl.add(lv.Items[i].Caption..' - '..lv.Items[i].SubItems[0]..' - '..lv.Items[i].SubItems[1])
          end
        end

        writeToClipboard(sl.Text)

        sl.destroy()
      end


      f.PopupMenu1.Items.add(mi)
      t.destroy()
    end;

  end
end)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Jun 14, 2016 10:27 am    Post subject: Reply with quote

Not sure exactly how lua handles this, but all I know is that the OnClick function will execute a long time after this script has finished (so likely also cleaned up some local vars)

Perhaps it works as it's in the context, but I don't know if that's to be trusted

_________________
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: 218

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

PostPosted: Tue Jun 14, 2016 11:43 am    Post subject: Reply with quote

lexical scoping
closures
https://www.lua.org/pil/6.1.html

_________________
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