 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Aylin Grandmaster Cheater
Reputation: 10
Joined: 16 Feb 2017 Posts: 644
|
Posted: Wed May 22, 2019 6:44 pm Post subject: I need a suggestion |
|
|
Hi,
I have the following code installed into the Trainer.
Working properly.
I've set the blank lines to be out of hack.
Question: The scenario in "b1.OnClick"
Should I do different?
For "b1.OnClick", I am looking for different ideas.
Code: | local f = createForm(true)
f.Position = poDesktopCenter
f.Width = 105
f.Height = 160
local l1 = createLabel(f)
l1.Left = 40
l1.Top = 5
l1.Font.Style = "fsBold"
l1.Font.Size = 10
l1.caption = "Value?"
local e1 = createEdit(f)
e1.Height = 24
e1.Left = 30
e1.Top = 25
e1.Width = 70
e1.OnChange = e1.Change
e1.OnClick = e1.Click
local e2 = createEdit(f)
e2.Height = 24
e2.Left = 30
e2.Top = 55
e2.Width = 70
local e3 = createEdit(f)
e3.Height = 24
e3.Left = 30
e3.Top = 85
e3.Width = 70
local b1 = createButton(f)
b1.Left = 30
b1.Top = 120
b1.Width = 70
b1.Font.Style = "fsBold"
b1.Font.Size = 10
b1.caption = "OFF"
-----------------------------------
b1.OnClick = function()
b1.caption = "Wait"
if e1.Text=='' then
e1.Text=''
else
e1Hack() end
if e2.Text=='' then
e2.Text=''
else
e2Hack() end
if e3.Text=='' then
e3.Text=''
else
e3Hack() end
b1.caption = "ON"
end
f.OnMouseDown = function() f.DragNow() end |
Thank you for your rare ideas.
_________________
Hi Hitler Take control of your trainer
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
 |
|
Back to top |
|
 |
FreeER Grandmaster Cheater Supreme
Reputation: 42
Joined: 09 Aug 2013 Posts: 1089
|
Posted: Wed May 22, 2019 10:06 pm Post subject: |
|
|
looks like you're just checking
if x is y then x = y --[[ aka do nothing --]] else dothing() end
So all you really care about is the else case...so just check
if x is not y then dothing() end
ie.
Code: | if e1.Text ~= '' then e1Hack() end
if e2.Text ~= '' then e2Hack() end
if e3.Text ~= '' then e3Hack() end |
though you could also do something more advanced like
Code: | for i = 1, 3 do
if _G['e'..i].Text ~= '' then _G['e'..i..'Hack']() end
end |
Where _G is the name of a table that refers to the global environment so 'e'..i is e1, e2, etc. and 'e'..i..'Hack' is e1Hack, e2Hack etc.
or slightly simpler with Code: | local texts = {e1, e2, e3}
local do_hacks = {e1Hack, e2Hack, e3Hack}
for i, t in ipairs(texts) do
if t.Text ~= '' then do_hacks[i]() end
end |
Either way the idea is to look at what's the same and what's different and factor out the different things into variables so that you're typing the common code only once.
_________________
|
|
Back to top |
|
 |
Aylin Grandmaster Cheater
Reputation: 10
Joined: 16 Feb 2017 Posts: 644
|
Posted: Thu May 23, 2019 9:06 am Post subject: |
|
|
Thanks @freeER. This was the result I was looking for.
Code: | b1.OnClick = function()
b1.caption = "Wait!"
local texts = {e1, e2, e3}
local do_hacks = {e1Hack, e2Hack, e3Hack}
for i, t in ipairs(texts) do
if t.Text ~= '' then do_hacks[i]() end
b1.caption = "ON"
end
end |
Why did I ask for advice: There were some contractions.
Now it is working smoothly and no contraction.
Thanks for suggestions and training.
and +1 Master..
_________________
Hi Hitler Take control of your trainer
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
 |
|
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
|
|