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 


Call Function Using External Button

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Game Hacking Dojo
Expert Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 109

PostPosted: Wed May 01, 2024 9:40 am    Post subject: Call Function Using External Button Reply with quote

How do I call functions I defined in an autorun Lua file that I want to call using another autorun Lua file that adds buttons to the UI and calls the functions already defined in the other script?

Yes, the functions are not "local"

When I call the functions using the Lua engine they work but when I use the buttons they do not work.

Code:
local SymbolsBtn = createMenuItem(MainForm)
SymbolsBtn.Name = 'SymbolsBtnExportSymbols'
SymbolsBtn.Caption = 'Export Symbols'
SymbolsBtn.OnClick = exportMainSymbols
miExtensions.add(SymbolsBtn)

local StringsBtn = createMenuItem(MainForm)
StringsBtn.Name = 'StringsBtnExportReferencedStrings'
StringsBtn.Caption = 'Export Referenced Strings'
StringsBtn.OnClick = pcall(createRefrencedFile,'s')
miExtensions.add(StringsBtn)

local FunctionsBtn = createMenuItem(MainForm)
FunctionsBtn.Name = 'FunctionsBtnExportReferencedFunctions'
FunctionsBtn.Caption = 'Export Referenced Functions'
FunctionsBtn.OnClick = pcall(createRefrencedFile,'f')
miExtensions.add(FunctionsBtn)


If I add this snippet to the file where it was originally defined it works.

Thank you
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 143

Joined: 06 Jul 2014
Posts: 4354

PostPosted: Wed May 01, 2024 10:55 am    Post subject: Reply with quote

`exportMainSymbols` isn't defined when this script is run.
(technically, it might be, but that depends on the load order of the scripts)

A wrapper function should work:
Code:
SymbolsBtn.OnClick = function(...)
  exportMainSymbols(...)
end
This forces Lua to look up the name when the wrapper function is run instead of when the script is run.
_________________
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
Game Hacking Dojo
Expert Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 109

PostPosted: Wed May 01, 2024 12:34 pm    Post subject: Reply with quote

Yup, that worked. Thank you.
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 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