Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


I need a suggestion

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Aylin
Grandmaster Cheater
Reputation: 10

Joined: 16 Feb 2017
Posts: 644

PostPosted: Wed May 22, 2019 6:44 pm    Post subject: I need a suggestion Reply with quote

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
View user's profile Send private message MSN Messenger
FreeER
Grandmaster Cheater Supreme
Reputation: 42

Joined: 09 Aug 2013
Posts: 1089

PostPosted: Wed May 22, 2019 10:06 pm    Post subject: This post has 1 review(s) Reply with quote

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.

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Aylin
Grandmaster Cheater
Reputation: 10

Joined: 16 Feb 2017
Posts: 644

PostPosted: Thu May 23, 2019 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites