|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
jonaskp Newbie cheater Reputation: 0
Joined: 29 May 2020 Posts: 14
|
Posted: Mon Jan 24, 2022 2:16 am Post subject: Loop in LUA won't start first time code runs. |
|
|
So I have a weird issue, and I don't know what to look for when troubleshooting.
I have a piece of code, with a userform, that runs in a loop every second, uploading the values from the cheat table to a database.
This part is working fine.
The weird issue is that the loop won't start running the first time I run the code (after every Cheat Engine Restart). Only when I run the code, close the userform, and run it again, everything start working as intended.
It's probably because I am missing something essential about LUA Scripting.
I mainly code in VBA, and have done some HTML/PHP/Javascript, but LUA is only used for this one project, so I probably just don't understand it enough.
Steps to reproduce:
1. Open the Cheat table.
2. "Show Cheat Table LUA script"
3. Click "Execute Script".
4. Userform opens (with name "UDF-3")
5. Loop doesn't run. Manually starting or stopping (using userform buttons) doesn't work either
6. Close the userform
7. Click "Execute Script" again
8. Userform opens (with name "UDF-5")
Loop runs as expected, and I can stop and restart it using userform buttons.
The same behavior happens if I open the Cheat Table and clicks "Yes" when the popup asks me to "Execute this LUA Script".
Can someone help me with what is wrong?
It is probably something trivial, because I am structuring my LUA code badly.
Code I am using (I have removed the database part, so right now the code just loops and continously adds 1 to the counter on the userform):
Code: |
if f then f.Destroy() end
if repeat_timer then repeat_timer.destroy() end
-------------------------------------------- GUI
--Setup the Form
f = createForm()
b1 = createButton(f)
b1.setPosition(10,10)
b1.Caption = 'Execute'
b2 = createButton(f)
b2.setPosition(10,50)
b2.Caption = 'Stop'
lblTimes = createLabel(f)
lblTimes.left = 10
lblTimes.top = 150
lblTimes.font.color = '0x000000'
lblTimes.caption = 0
chk1 = createCheckBox(f)
chk1.setPosition(10,100)
chk1.Caption = 'Include full playernames (setup only)'
chk1.Checked = false
-------------------------------------------
--Attach the process
aalist=getAutoAttachList()
stringlist_add(aalist,"FIFA22.exe");
repeat_timer = createTimer()
repeat_timer.Interval = 500
repeat_timer.OnTimer = execute
b1.OnClick = execute
b2.OnClick = stopExecute
bExit.OnClick = ExitFunction
function stopExecute()
repeat_timer.Enabled = false
end
function execute()
repeat_timer.Enabled = true
local al=getAddressList()
local strSQLCommand=""
local strDescription=""
local strValue=""
local strPCnumber="PC1"
local lNumberOfTimes = 0
--This is where the upload to Database happens
lNumberOfTimes = lblTimes.caption + 1
lblTimes.caption = lNumberOfTimes
::StopCode::
end |
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Mon Jan 24, 2022 3:02 am Post subject: |
|
|
Code: |
b1.OnClick = execute
b2.OnClick = stopExecute
bExit.OnClick = ExitFunction
|
The first time this code runs execute stopExecute and Exitfunction have not been defined yet, so they are nil
Move these functions above your code
_________________
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 |
|
|
jonaskp Newbie cheater Reputation: 0
Joined: 29 May 2020 Posts: 14
|
Posted: Mon Jan 24, 2022 7:36 am Post subject: |
|
|
Thanks a lot, this seems so easy and trivial now that I know
So when executing the script, it runs all the code that is not inside of a function - and it doesn't look for functions names later in the entire code, but runs the code from the top only.
Good to know, I will remember to keep functions at the top.
|
|
Back to top |
|
|
|
|
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
|
|