| View previous topic :: View next topic |
| Author |
Message |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Mon Feb 21, 2022 3:13 pm Post subject: Why would table code "compile", but not run? |
|
|
In another thread, I noted that one of my table codes was "compiling", but not running. I inserted a print statement at the beginning of the code to allow the debug window to be visible since the code has print statements towards the end that don't print. If I then type in a main overall function, everything "seems to work". The cheat panel appears, when did not during the initial load. Table execution is set to "Always"
Does anyone besides me thin this is odd behavior?
|
|
| Back to top |
|
 |
ByTransient Expert Cheater
Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Mon Feb 21, 2022 5:49 pm Post subject: |
|
|
Try putting "print" inside all "if" statements to see the progress when you activate a function.
| Code: | function example()
print(1)
if .. then
print(2)
end
if .. then
print(3)
end
end |
-- etc ..
So you'll see what steps the function is following when it's activated.
|
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Feb 21, 2022 8:10 pm Post subject: |
|
|
I believe Lua provides a debug library, which provides all the primitive functions for us to create our own debugger.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Mon Feb 21, 2022 9:40 pm Post subject: |
|
|
Maybe I'm not describing the question.
https://forum.cheatengine.org/viewtopic.php?p=5777066#5777066
This is the table and previous question, you may look at the code, it is too long to post twice. Anyway, here is a screen shot of my table and the debug window triggered by the first line of code now. Then I type the first function of the table in the debug window and hit execute. Notice that the Cheat Panel is now showing after that execution. Many but not all work now. I obtain no error warnings when opening the table, nor when it runs trainer:star().
treainer:start is line 78,
these are code lies 738 and 739. | Code: |
self.form.show();
print("God mode is not enabled");
|
I don't understand. Maybe DB might have an idea.
| Description: |
|
| Filesize: |
384.5 KB |
| Viewed: |
3760 Time(s) |

|
| Description: |
|
| Filesize: |
388.26 KB |
| Viewed: |
3760 Time(s) |

|
|
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Sat Feb 26, 2022 10:26 am Post subject: |
|
|
As an update to this question, I have started with blank tables one used the edit function to build a similar table; and two build every object with code. In both of these test cases the code compiled and showed the CheatPanel. So, it seems(?) there was something in the addresses that prevented the code compiling and displaying the CheatPanel.
ETA: And the above is incorrect, I believe it is the tstop timer that is the issue. If I delete completely or put it at the end of the code the table pops up during load.
|
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Mon Mar 07, 2022 12:39 pm Post subject: |
|
|
I've been going through the code and it does work but there are a couple of small issues that I have not been able to correct. I'm not going to post the wall of code since it does work.
| Code: |
memrec6 = addresslist_getMemoryRecord(addresslist, x);--Item in hex format without the 0x
if byteoffset ~= goldtableaddress then
memoryrecord_setAddress(memrec6, string.format('%x', memoryrecord_getAddress(memrec6) + byteoffset - goldtableaddress));
end;
end;
|
This is the end of the recalculate function, that works! There is a print statement several lines before the code I have pasted. The print statement is executed and the addresses are adjusted in the if statement No problems up till this point.
| Code: |
recalc = 1;
expvalue = nil
goldvalue = nil
--heroname = nil
byteoffset = nil
trainer.exp_value.Text = "";
trainer.gold_value.Text = "";
--trainer.HeroOneEdit.Text = "";
--trainer.HeroTwoEdit.Text = "";
--trainer.HeroThreeEdit.Text = "";
--trainer.HeroFourEdit.Text = "";
--trainer.HeroFiveEdit.Text = "";
--trainer.HeroSixEdit.Text = "";
--trainer.profession_rg.ItemIndex = 0;
trainer.characters_rg.ItemIndex = 0;
tde.Enabled = true;
| Between the above mentioned print statement(not shown) and prior to the print statement below I get an Error:Invalid class object. There are only two code lines as everything else has been commented out. The first is to set the rg to 0 the second is to enable a timer which is coded just before the recalculate function. This timer displays hero levels and that function is coded before the timer. What is the error?
| Code: |
print("The table has been recalculated")
end--function RecalculateAddresses() |
After the print statement,"The table has been recalculated", I get another error Error:Access violation. I can only think that the DisplayEdits function is causing this. These are the DisplayEdits code and the timer.
| Code: |
function DisplayEdits()
local AL = getAddressList()
FirstLevel = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "1st Level"))
trainer.HeroOneEdit.Text = FirstLevel
SecondLevel = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "2nd Level"))
trainer.HeroTwoEdit.Text = SecondLevel
ThirdLevel = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "3rd Level"))
trainer.HeroThreeEdit.Text = ThirdLevel
FourthLevel = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "4th Level"))
trainer.HeroFourEdit.Text = FourthLevel
FifthLevel = memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "5th Level"))
trainer.HeroFiveEdit.Text = FifthLevel
SixthLevel= memoryrecord_getValue(addresslist_getMemoryRecordByDescription(AL, "6th Level"))
trainer.HeroSixEdit.Text = SixthLevel
end--function DisplayEdits(
--
tde = createTimer(nil, true)
timer_onTimer(tde, DisplayEdits)
timer_setInterval(tde, 1000)
timer_setEnabled(tde, false)
| The edit boxes don't display the levels, however after running the recalculate function I type in DisplayEdits() the debug window and execute, all boxes display the levels.
What can be in error to cause the access violation?
There is another error after selecting a level and adjusting the exp but I'll save that for my next post.
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1531
|
Posted: Mon Mar 07, 2022 6:23 pm Post subject: |
|
|
One caveat: sorting and locales are within a single function and not global.
You do as shown below:
| Code: |
self.gm_cb.onClick = function (sender)
if sender.Checked then
self.t.Enabled = true; --This directive (name) does not have a timer. If you mean "t", you should create "t" above and just be named "t". t.Enabled=false
print("God mode is enabled")
else
self.t.Enabled = false;
print("God mode is not enabled")
end
end
-- ...
-- ...
tde = createTimer(nil, true)
timer_onTimer(tde, DisplayEdits) --This is an unassigned function
timer_setInterval(tde, 1000)
timer_setEnabled(tde, false)
t = createTimer(nil, true)
timer_onTimer(t, MaxHP) --And.. This is an unassigned function
timer_setInterval(t, 1000)
timer_setEnabled(t, false)
function RecalculateAddresses()
--...
-- ...
tde.Enabled = true;
print("The table has been recalculated")
function DisplayEdits()
-- ...
end
function MaxHP(sender)
-- ...
end
-- ...
-- ...
function FindDescriptions()
-- ...
end
end --RecalculateAddresses finish !!! |
Here's a suggestion:
| Code: | t = createTimer(nil, true)
timer_setInterval(t, 1000)
timer_setEnabled(t, false)
self.gm_cb.onClick = function (sender)
if sender.Checked then
t.Enabled = true;
print("God mode is enabled")
else
t.Enabled = false;
print("God mode is not enabled")
end
end
-- ...
-- ...
tde = createTimer(nil, true)
timer_setInterval(tde, 1000)
timer_setEnabled(tde, false)
function RecalculateAddresses()
tde.Enabled = true;
print("The table has been recalculated")
function DisplayEdits()
-- ...
end
timer_onTimer(tde, DisplayEdits)
function MaxHP(sender)
-- ...
end
timer_onTimer(t, MaxHP)
-- ...
-- ...
function FindDescriptions()
-- ...
end
end --RecalculateAddresses finish |
Or I'm wrong.
_________________
|
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Tue Mar 08, 2022 7:32 am Post subject: |
|
|
As to the placement of tde timer, I was attempting to follow DB's advice to compile a function prior to calling it. Since the timer is set to not enabled until the recalculate function is executed, I guess it can be placed before the DisplayEdits. Same logic with the t timer, again it isn't enabled until recalculate function is executed. I will move them later today and report results.
ETA: Moved both of the timers as suggested no resultant change from previous behaviors, although I didn't attempt to use t timer.
The same error messages at the end of the recalculate function. I wonder if a change from tde = createTimer(nil, true). to trainer.tde = createTimer(nil, true) would make any difference?
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1531
|
Posted: Tue Mar 08, 2022 10:10 am Post subject: |
|
|
My advice is to exclude possible functions (DisplayEdits, MaxHP) from recalculation.
And for unordered use, include it in the table:
| Code: | function trainer.RecalculateAddresses()
--...
-- ...
tde.Enabled = true;
print("The table has been recalculated")
end
function trainer.DisplayEdits()
-- ...
end
timer_onTimer(tde, DisplayEdits)
function trainer.MaxHP(sender)
-- ...
end |
Make sure they are dead when you re-enable the script.
Put a death blow at the beginning of the creation code.
| Code: | if tde then tde.Destroy() tde=nil end
tde = createTimer(nil, true)
timer_onTimer(tde, trainer.DisplayEdits) --This is an unassigned function
timer_setInterval(tde, 1000)
timer_setEnabled(tde, false) |
_________________
|
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Tue Mar 08, 2022 3:52 pm Post subject: |
|
|
There are no duplicate code lines in the Recalculate function. There is one address is accessed memrec5 = addresslist_getMemoryRecordByDescription(addresslist, heroname .. " Gold");. All the memrecx occur in Recalculate and nowhere else. I don't know if there is any difference in the getAddressList that occur in the tabble, but DisplayEdits have an AL and Recaclculate and MaxHP both use addresslist. I could change the Reccalculate function one to something else easily since it involves one code line, MaxHP alreadeay has a local addresslist, same with DisplayEdits.
I have been tinkering today. I believe you worote once if the code is read it will be executed. I guess I might add that the code must be correctly syntaxed or it won't be read.
This is my first read, maybe I glossed over:timer_onTimer(tde, trainer.DisplayEdits) The trainer.DisplayEdits part.
As a sidenote I have not opened MaxHP, since I have had the issues with DisplayEdits.
ETA Question
There is a function trainer:start() immediately following the data tables.
Currently the function Display edits and tde timer follow the end--trainer:start.
Should the timer and edit boxes be referenced as trainer.xxxxx or just xxxx?
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1531
|
Posted: Tue Mar 08, 2022 5:43 pm Post subject: |
|
|
1) For regular use; It's good to specify the occurrence at the beginning and use it later. This fixes many bugs.
2) You have to kill the timer first and then generate it.
| Code: | if tde then tde.Destroy() tde=nil end
tde = createTimer(nil, true) |
3) Rather than linking to a table, note this:
If you create the timer inside a function, you use it inside that function. You cannot "Enabled=true or false" in a different function.
If necessary, define timers in the first row before creating all tables. Then before activating, you assign like "tde.OnTimer=DisplayEdits; tde.Enabled=true".
The important thing is to have the script see that function before assigning the function to the scheduler.
Here's a priority test:
1)
| Code: | table1={}
table1.tdeFunc=function() print("Lua") end
if tde then tde.Destroy() tde=nil end
tde = createTimer(nil, true)
tde.Interval=2000
tde.OnTimer=table1.tdeFunc
function table1.tdeFunc()
print("hello")
end
tde.Enabled=true |
result: print .. Lua
2)
| Code: | table1={}
table1.tdeFunc=function() print("Lua") end
if tde then tde.Destroy() tde=nil end
tde = createTimer(nil, true)
tde.Interval=2000
tde.OnTimer=table1.tdeFunc
function table1.tdeFunc1()
print("hello")
end
tde.OnTimer=table1.tdeFunc1
tde.Enabled=true |
result: print .. Hello
_________________
|
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Tue Mar 08, 2022 6:59 pm Post subject: |
|
|
Interesting bit of information. My tde wasn't in a function , but the DisplayEdits was/is the original function that created all the objects Would that be an issue calling a function "inside" another?
Since my last post, I have commented out the two lines prior to the print statement "The table is recalculated" I've done this so many times this evening both error messages disappeared. Putting them back into the code the one at a time trainer.characters_rg.ItemIndex = 0 caused the invalid class object, but the index was set to No One. The timer is another issue as I put a print statement inside the DisplayEdits following the function line, and it was never hit. Conclusion the timer either doesn't work inside/outside functions or not at all.
I haven't tried putting tde at the beginning, yet. Just starting a demo will report back later.
ETA I moved the tde time to the beginning of the code and moved DisplayEdits out of any function. Saved/shut down/reopened. Recalculate the table same error messages with rg setting to 0. No print from the second line in DisplayEdits function.
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1531
|
Posted: Tue Mar 08, 2022 7:43 pm Post subject: |
|
|
Message me the final edited version of the table.
Let me remind you; I always open it in 7.4 and I recommend you to try the results in both versions.
Let's make time for that tomorrow. I hope we get the final result.
_________________
|
|
| Back to top |
|
 |
|