| View previous topic :: View next topic |
| Author |
Message |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Thu Nov 26, 2020 3:04 pm Post subject: messageDialog() cancel closing of AA script ? |
|
|
Hi,
is there a way to prevent the closing of an AA script via LUA messageDialog ?
LUA Script:
| Code: |
function testMe(params, syntaxcheck)
local bResult = messageDialog("Some Error, you want close the script?", mtError, mbYes, mbNo)
--pseudo code
-- if bResult == mbYes then
-- close AA script window
-- else
-- cancel the closing of AA script window
-- end
end
registerAutoAssemblerCommand('testMe', testMe)
|
AA Script:
| Code: |
[ENABLE]
testMe()
[DISABLE]
|
hope you get the idea
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25832 Location: The netherlands
|
Posted: Thu Nov 26, 2020 3:30 pm Post subject: |
|
|
find the AA form used for that script and then override the OnCloseQuery property.
Make it return false if you don't want to allow it to be closed
_________________
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 |
|
 |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Thu Nov 26, 2020 4:45 pm Post subject: |
|
|
Pewww, what a puzzle...
ok, first approach:
LUA Script:
| Code: |
function testMe(params, syntaxcheck)
local frm = nil
for i = 0, getFormCount() - 1 do
frm = getForm(i)
if frm.Caption == "Auto Assemble edit: TestMe" then
break
end
end
if frm ~= nil then
frm.OnCloseQuery = function()
return false
end
end
end
|
This works like a charm, you can't close the AA script anymore ^^
But how do i get the "sender" AA script single name without iteration?
| Quote: | | find the AA form used for that script |
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25832 Location: The netherlands
|
Posted: Fri Nov 27, 2020 12:45 am Post subject: |
|
|
getForm(0) is the top window and the higher you go the deeper in the z-level you go.
so it's reasonable to assume the first aa window is the one you're interested in. (check ClassName if it is 'TfrmAutoInject')
Assuming that you run that script manually and not from a memoryrecord activate event, as there is no autoassembler window assigned then
_________________
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 |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Fri Nov 27, 2020 1:51 am Post subject: |
|
|
Get description (from memrec) and pass it as params in your script
| Code: | {$LUA}
return ("define(memrecDesc,%s)"):format(memrec.Description);
{$ASM}
[ENABLE]
testMe(memrecDesc)
[DISABLE] |
And then testMe would look like this
| Code: | function testMe(params, syntaxcheck)
local frm = nil
for i = 0, getFormCount() - 1 do
frm = getForm(i)
if frm.Caption == ("Auto Assemble edit: %s"):format(params) then
break
end
end
if frm ~= nil then
frm.OnCloseQuery = function()
return true
end
end
end
registerAutoAssemblerCommand('testMe', testMe) |
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Fri Nov 27, 2020 9:34 am Post subject: |
|
|
| Great answers. Thank you both.
|
|
| Back to top |
|
 |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Fri Nov 27, 2020 5:49 pm Post subject: |
|
|
Have to add something:
if a LUA Error occurs or you use print(), the Lua Engine form window is going to pop top.
so if you use
is not a good idea ^^
but this is working at the moment:
| Code: | local function _getForm()
local frm = nil
for i = 0, getFormCount() - 1 do
frm = getForm(i)
if frm.ClassName == 'TfrmAutoInject' then
return frm
end
end
if DEBUG then print('DEBUG: _getForm(): could not get active form!') end
return nil
end |
@DaSpamer
your define(sender) example is good, but i try to avoid as much lua code in the AA script as possible....
Great thing would be, if you click on the OK Button in AA script, and there is a LUA event / listener / callback....
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25832 Location: The netherlands
|
Posted: Fri Nov 27, 2020 6:49 pm Post subject: |
|
|
| Quote: |
Great thing would be, if you click on the OK Button in AA script, and there is a LUA event / listener / callback....
|
| Code: |
function forEachAndFutureForm(classname, func)
local i
for i=0,getFormCount()-1 do
local f
f=getForm(i)
if f.ClassName==classname then
func(f)
end
end
registerFormAddNotification(function(f)
if classname==f.ClassName then
f.registerCreateCallback(func)
end
end)
end
forEachAndFutureForm('TfrmAutoInject',function(f)
local originalExecute=f.btnExecute.OnClick
f.btnExecute.OnClick=function(sender)
--f.Assemblescreen.Lines.Text contains the script
print("Before execute")
originalExecute(sender)
print("After execute")
end
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 Fri Nov 27, 2020 7:18 pm; edited 1 time in total |
|
| Back to top |
|
 |
Reaper79 Advanced Cheater
Reputation: 2
Joined: 21 Nov 2013 Posts: 68 Location: Germany
|
Posted: Fri Nov 27, 2020 7:13 pm Post subject: |
|
|
| Woho, thank you ^^
|
|
| Back to top |
|
 |
|