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 


How can I select a menu option from CE with Lua

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

Joined: 21 Feb 2016
Posts: 115

PostPosted: Thu Nov 03, 2016 4:20 am    Post subject: How can I select a menu option from CE with Lua Reply with quote

I need a button in my trainer that can select one of the menu options from the main CE window that I populated myself, for example Plugins > Execute plugin .dll or Extras > Execute plugin .lua (so basically like a key shortcut but with an OnClick event instead), is there a way I can do this?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Thu Nov 03, 2016 4:40 am    Post subject: Reply with quote

if you gave the menuitem a name property you can basically do getMainForm().menuitemname.doClick()

if not, then you have to walk through the menu list manually looking for the caption. ( the getMainForm().MainMenu.Items tree)

or if you added the menuitem with lua, you can just keep a reference to it somewhere so your button can find it

_________________
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
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Thu Nov 03, 2016 5:35 am    Post subject: Reply with quote

Thanks DB getMainForm was what I was looking for.

Code:
function PluginsClick()
  getMainForm().Menu.Items[7][0].doClick()
end
Back to top
View user's profile Send private message
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 206

PostPosted: Fri Nov 20, 2020 9:21 am    Post subject: Accessing menu_item by name... Reply with quote

@Dark Byte: tried and... error-ed... (did try some other 'index' approaches too)
I assume this is what you mean with giving it a name (see below)? (even tried without apostrophes (CE did not complain), but still no-go...?)
ps: the "array_index" method works fine, but that is not what I really want (~ readability .. future_ce_updates)

[code]
OpenFilemenuitem = createMenuItem(mmenu)
OpenFilemenuitem.Caption = sMenuItem4
OpenFilemenuitem.OnClick = OpenFileDialog
OpenFilemenuitem.Name = 'LaunchGame'
mi.add(OpenFilemenuitem)

...

--getMainForm().Menu.Items[11][2].Enabled = false (...works fine)
--OpenFilemenuitem.Enabled = false (...works fine, after some serious T&E Cool )
getMainForm().LaunchGame.Enabled = false
OR
getMainForm()['LaunchGame'].Enabled = false
OR
getMainForm().OpenFilemenuitem.Enabled = false
[/code]

=> ...attempt to index a nil value (field 'OpenFilemenuitem') (~in that last case)


Directly related to this: is it possible to easily "remove" a (main) menuItem. Practically: one adds a new menu (with some (sub)menu_items) to the MainMenu. But depending some "flag_status", this menu should be shown or not. Tried 'nil/destroy()'-ing that menu_item, but nogo. However, this seems to work on any of the submenu_items.
(i'm beginning to think, it is more a matter of getting the Mainmenu 'refresh'-ed somehow...?)
ps: just checked the item's Propertylist: perhaps I could use the 'Visible' property for this purpose...


FYI: logically, my menuItem would be at [5][x] (in Mainmenu], but this was/is not the case. Ran a script from #panraven, which builds a list of all menu_items (easypeasy Smile)...
Back to top
View user's profile Send private message
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