View previous topic :: View next topic |
Author |
Message |
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Wed Jul 31, 2013 8:02 pm Post subject: Debugging Lua script [CE modification, autorun] |
|
|
For those who are debugging/testing trainers (trainer saved as CT file).
Try to execute this example script:
Code: | RequiredCEVersion=6.3
if (getCEVersion==nil) or (getCEVersion()<RequiredCEVersion) then
messageDialog('Please install Cheat Engine '..RequiredCEVersion, mtError, mbOK)
closeCE()
end
addresslist=getAddressList()
variable1 = 32423
variable2 = 32423
form_show(notExist) -- Obvious, not like form_show(ShowCheatIist)
function AboutClick()
showMessage(gAboutText)
end
gAboutText=[[This trainer was made by Cheat Engine
www.cheatengine.org]] |
You will get "undefined lua error" message window and "Error:Invalid class object" string inside log output of "Lua Engine" window. Obviously, it is notExist variable's fault. But, if you have "wall of text", it is hard to catch typos like like this: you typed in form_show(ShowCheatIist) instead of form_show(ShowCheatlist).
My script (move it to autorun):
Code: | function trace(event, line)
local s = debug.getinfo(2).short_src
if not s:match('%[string') then return end
DebugLabel.Caption = "last line executed: "..line
end
frmLuaTableScript = getMainForm().frmAutoInject
frmLuaTableScriptPanel1OnResizeOLD = frmLuaTableScript.Panel1.OnResize
frmLuaTableScript.Panel1.OnResize = function (sender)
frmLuaTableScriptPanel1OnResizeOLD(sender)
DebugButton.Top = Button.Top - 8
DebugButton.Left = Button.Left + 50
DebugLabel.Top = Button.Top + 18
DebugLabel.Left = Button.Left + 55
Button.Left = Button.Left - 80
end
debugOnOffFlag = false
Button = frmLuaTableScript.Button1
Button.AutoSize = true
DebugLabel = createLabel(frmLuaTableScript.Panel1)
DebugLabel.AutoSize = true
DebugLabel.Caption = "debug disabled"
DebugButton = createButton(frmLuaTableScript.Panel1)
DebugButton.AutoSize = true
DebugButton.Caption = "Find faulty line"
DebugButton.Height = Button.Height
DebugButton.OnClick = function ()
debugOnOffFlag = not debugOnOffFlag
if debugOnOffFlag then debug.sethook(trace, "l")
DebugButton.Font.Style = '[fsBold]'
DebugLabel.Caption = "last line executed:"
else debug.sethook()
DebugButton.Font.Style = '[]'
DebugLabel.Caption = "debug disabled"
end
end
|
Now, you will have additional Button, called "Find faulty line". Click it, it gets bold and label shows "last line executed". Click "Execute script". You will get the same error messages and message window. But, this time you will get "last line executed" info.
In this case: "last line executed: 12"
Edit1:
added comments.
EDIT2:
newest version of this script here LINK
Description: |
|
Download |
Filename: |
LuaDebug_FindFaultyLine.lua |
Filesize: |
1.85 KB |
Downloaded: |
1150 Time(s) |
_________________
Last edited by mgr.inz.Player on Sun Aug 11, 2013 12:02 pm; edited 3 times in total |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Thu Aug 01, 2013 9:46 am Post subject: |
|
|
thanks if i could rep u again i would but need to find some else before i can rep u again
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu Aug 01, 2013 10:07 am Post subject: |
|
|
Thanks
_________________
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Thu Aug 01, 2013 10:09 am Post subject: |
|
|
lets hope this will be in the next ce version or build.
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Thu Aug 01, 2013 10:13 am Post subject: |
|
|
From other thread:
Dark Byte wrote: | I once looked into it but it resulted in a even worse bug, but i'll see (perhaps the debug.hook function might be useful here to see the last called function) |
Maybe now he can overcome this problem.
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Aug 11, 2013 10:24 am Post subject: |
|
|
Small update:
- different button positions...
- extra info about function name
Code: | function trace(event, line)
local s = debug.getinfo(2).short_src
local name = debug.getinfo(2).name
name = name and ' ( func '..name..' )' or ''
if not s:match('%[string') then return end
DebugLabel.Caption = "last line executed: "..line..name
end
frmLuaTableScript = getMainForm().frmAutoInject
frmLuaTableScriptPanel1OnResizeOLD = frmLuaTableScript.Panel1.OnResize
frmLuaTableScript.Panel1.OnResize = function (sender)
frmLuaTableScriptPanel1OnResizeOLD(sender)
Button.Left = Button.Left - 110
DebugButton.Top = Button.Top
DebugButton.Left = Button.Left + 120
DebugLabel.Top = Button.Top + 4
DebugLabel.Left = Button.Left + 250
end
debugOnOffFlag = false
Button = frmLuaTableScript.Button1
Button.AutoSize = true
DebugLabel = createLabel(frmLuaTableScript.Panel1)
DebugLabel.AutoSize = true
DebugLabel.Caption = "debug disabled"
DebugButton = createButton(frmLuaTableScript.Panel1)
DebugButton.AutoSize = true
DebugButton.Caption = "Find faulty line"
DebugButton.Height = Button.Height
DebugButton.OnClick = function ()
debugOnOffFlag = not debugOnOffFlag
if debugOnOffFlag then debug.sethook(trace, "l")
DebugLabel.Caption = "last line executed:"
else debug.sethook()
DebugLabel.Caption = "debug disabled"
end
end
|
_________________
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Sun Aug 11, 2013 10:33 am Post subject: |
|
|
mgr.inz.Player wrote: | Small update:
- different button positions...
- extra info about function name
Code: | function trace(event, line)
local s = debug.getinfo(2).short_src
local name = debug.getinfo(2).name
name = name and ' ( func '..name..' )' or ''
if not s:match('%[string') then return end
DebugLabel.Caption = "last line executed: "..line..name
end
frmLuaTableScript = getMainForm().frmAutoInject
frmLuaTableScriptPanel1OnResizeOLD = frmLuaTableScript.Panel1.OnResize
frmLuaTableScript.Panel1.OnResize = function (sender)
frmLuaTableScriptPanel1OnResizeOLD(sender)
Button.Left = Button.Left - 110
DebugButton.Top = Button.Top
DebugButton.Left = Button.Left + 120
DebugLabel.Top = Button.Top + 4
DebugLabel.Left = Button.Left + 250
end
debugOnOffFlag = false
Button = frmLuaTableScript.Button1
Button.AutoSize = true
DebugLabel = createLabel(frmLuaTableScript.Panel1)
DebugLabel.AutoSize = true
DebugLabel.Caption = "debug disabled"
DebugButton = createButton(frmLuaTableScript.Panel1)
DebugButton.AutoSize = true
DebugButton.Caption = "Find faulty line"
DebugButton.Height = Button.Height
DebugButton.OnClick = function ()
debugOnOffFlag = not debugOnOffFlag
if debugOnOffFlag then debug.sethook(trace, "l")
DebugLabel.Caption = "last line executed:"
else debug.sethook()
DebugLabel.Caption = "debug disabled"
end
end
|
|
It seems to not display the name var.
Only line, is it suppose to be that?
Also this line is required to executed, if you do not resize the Lua script window.
frmLuaTableScript.Panel1.OnResize()
+Rep, helps alot, thanks.
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Sun Aug 11, 2013 10:47 am Post subject: |
|
|
We don't have to call OnResize, this event occurs just after opening LuaTableScript window ("Lua Script: Cheat Table").
Quote: | It seems to not display the name var. |
It is function name for most of the time. And maybe something else...
Try this code:
Code: |
function testIt()
form_show(nihilNovi)
end
testIt() |
_________________
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Sun Aug 11, 2013 10:54 am Post subject: |
|
|
mgr.inz.Player wrote: | We don't have to call OnResize, this event occurs just after opening LuaTableScript window ("Lua Script: Cheat Table").
Quote: | It seems to not display the name var. |
It is function name for most of the time. And maybe something else...
Try this code:
Code: |
function testIt()
form_show(nihilNovi)
end
testIt() |
|
I execute it via the lua script window, so no wonder why it didn't change it's position .
Quote: |
function testIt()
form_show(nihilNovi)
end |
Seem to work (returns the full line).
Thanks .
_________________
|
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
|
Back to top |
|
|
bknight2602 Grandmaster Cheater Reputation: 0
Joined: 08 Oct 2012 Posts: 577
|
Posted: Sun Feb 27, 2022 6:54 am Post subject: |
|
|
So, copy this into what I call the debug window and execute? In other words NOT into the main script started by ctrl+alt+L.
ETA: Ok, there is a button created on the debug window. Pushed that button and the code seems to be in a loop printing out nothing of befit to me.
|
|
Back to top |
|
|
|