 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Jun 08, 2020 9:02 pm Post subject: Code Improvement 2 : Creating Multiple Objects (Label) |
|
|
From this topic :
https://forum.cheatengine.org/viewtopic.php?t=614442
The script below is a basic logic for a game call typing mania.
| Code: | if f then f.destroy() end
f = createForm()
label1 = createLabel(f)
label1.Font.Size = 20
label1.Left = math.random(5,200)
label2 = createLabel(f)
label2.Font.Size = 14
label2.Left = math.random(1,100)
local text1 = "REVEAL" -- will sub with words table
local text2 = "CHEAT ENGINE" -- will sub with words table
ctop1 = -40
ctop2 = -80
pos = f.Height - 40
function run()
--x = text:sub(1,z) -- if want make text trail animation
label1.Caption = text1
label2.Caption = text2
ctop1 = ctop1 + 1
ctop2 = ctop2 + 1
--if ctop1 > pos or ctop2 > pos then c.Enabled = false print('Done') end
label1.Top = ctop1
label2.Top = ctop2
end
c=createTimer(f)
c.Interval=50 --- decrease timer interval if reach some words
c.OnTimer= run
c.Enabled = true
run() |
Problems:
1. How to make multiple object labels (say it 100 labels) on the form without using (_G) global variable.
2. If the object labels has created, then the function 'run' will assist them to display on the form by their sequences.
For labels top and left position, we use math.random() function.
It is very nice if @Razi and/or @exohaxor should give the solutions for the problems. (This is just an opinion)
Cheers
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
exohaxor Expert Cheater
Reputation: 1
Joined: 02 Sep 2018 Posts: 101
|
Posted: Tue Jun 09, 2020 4:45 am Post subject: |
|
|
from what i understand you want to create a big number of labels like 100 and make them slide down this is what i did
| Code: |
if f then f.destroy() end
local amount = 20 --label amount
local words = {"hi", "hello", "sup", "xeome", "corroder", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"} --words
panels = {}
f = createForm()
for i = 1, amount do
table.insert(panels, createLabel(f))
end
for i = 1, #panels do
panels[i].Font.size = 20
panels[i].Caption = words[i]
panels[i].Top = math.random(1, amount) *- 20
panels[i].Left = math.random(1, amount) * 20
end
function run()
for i = 1, #panels do
panels[i].top = panels[i].top + 1
end
end
c = createTimer(f)
c.Interval = 100 --- decrease timer interval if reach some words
c.OnTimer = run
c.Enabled = true
run()
|
_________________
hi |
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1549
|
Posted: Tue Jun 09, 2020 5:04 am Post subject: |
|
|
Good job buddy. Congratulations.
A lot of work you do triggers new ideas.
Below is a "continuous flowing" text.
For example; If we make labels more and make stars other than text,
snowfall simulation can be obtained.
| Code: | if f then f.destroy() end
f = createForm()
label1 = createLabel(f)
label1.Font.Size = 20
label1.Left = math.random(5,200)
label2 = createLabel(f)
label2.Font.Size = 14
label2.Left = math.random(1,100)
local text1 = "*" -- will sub with words table
local text2 = "CHEAT ENGINE" -- will sub with words table
ctop1 = -40
ctop2 = -80
pos = f.Height - 40
function run()
--x = text:sub(1,z) -- if want make text trail animation
label1.Caption = text1
label2.Caption = text2
if label1.Top>f.Height + 30 then
label1.Top = f.Height - f.Height - 30
label2.Top = f.Height - f.Height - 60
ctop1 = -40
ctop2 = -80
else
ctop1 = ctop1 + 1
ctop2 = ctop2 + 1
--if ctop1 > pos or ctop2 > pos then c.Enabled = false print('Done') end
label1.Top = ctop1
label2.Top = ctop2
end
end
c=createTimer(f)
c.Interval=1 --- decrease timer interval if reach some words
c.OnTimer= run
c.Enabled = true
--run() |
A nice snowfall can be seen in the background of the trainer.
_________________
|
|
| Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Tue Jun 09, 2020 5:08 am Post subject: |
|
|
the only global is f var
| Code: | if f and f.destroy then f.destroy() f=nil end
f = createForm()
local label = createLabel(f)
label.setPosition(10,10)
label.Caption = 'whatever'
for i=1,100 do
local label = createLabel(f)
label.Font.Size = math.random(14,20)
label.Left = math.random(1,200)
label.Top = i*-40
label.Caption = math.random(100000,999999)
label.Tag = 1 -- default is zero, set to some special value to differentiate from other labels
-- e.g. tag==0 - do not move, tag==1 move label
end
local c=createTimer(f,false)
c.Interval=1
c.OnTimer= function ()
for i=f.ControlCount-1,0,-1 do
local object = f.Control[i]
if object.Tag==1 then
object.Top = object.Top + 1
if object.Top>f.Height then object.destroy() end
end
end
end
c.Enabled = true
|
_________________
|
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Tue Jun 09, 2020 6:04 am Post subject: |
|
|
| exohaxor wrote: | | from what i understand you want to create a big number of labels like 100 and make them slide down this is what i did |
Yes that is right, actually I have done making multiple objects in CE Form using Lua scripts and sometimes I use global variable for the object and sometimes not. Inside your code:
| Code: | for i = 1, amount do
table.insert(panels, createLabel(f))
end
for i = 1, #panels do
panels[i].Font.size = 20
panels[i].Caption = words[i]
panels[i].Top = math.random(1, amount) *- 20
panels[i].Left = math.random(1, amount) * 20
end
|
When you use table to create multiple panels and labels, that actually you assign global variable and that almost similar by using _G, because _G actually is a table.
And mgr.inz.Player code is shown that only 'f' (the form) as global variable. 100% Bravo.
Thank you to all of you to solve the problems.
EDIT:
I have a question to mgr.inz.Player, Is any chance we make the characters from a word falling down by their sequences (or random) to a position and then forming the original word at that position?. Something like text falling trail motion/animation like usually use on adobe after effects.
EDIT2:
This is what I mean, but I can't get FONT WIDTH using CE Lua script.
| Code: | function chars(str)
strc = {}
for i = 1, #str do
table.insert(strc, string.sub(str,i, i))
end
return strc
end
local str = 'THIS IS CHEAT ENGINE'
local cleft = 10
local char = chars(str)
local pos = 100
if f and f.destroy then f.destroy() f=nil end
f = createForm()
f.Position = 'poScreenCenter'
f.Width = 400
for i=1,#str do
local label = createLabel(f)
label.Font.Size = 18
label.Left = cleft
label.Top = i*-40
label.AutoSize = true
if (char[i] == " ") then
label.Caption = " "
else
label.Caption = char[i]
end
label.Tag = 1
cleft = cleft + 15
end
local c=createTimer(f,false)
c.Interval=1
c.OnTimer= function ()
for i=f.ControlCount-1,0,-1 do
local object = f.Control[i]
if object.Tag==1 then
object.Top = object.Top + 1
if object.Top>pos then object.Tag = 0 end
end
end
end
c.Enabled = true |
This part:
must be:
| Code: | | cleft = cleft + font.pitch or font.width |
SOLVE:
Nvm, just change here:
| Code: | | cleft = cleft + label.Width+1 |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| 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
|
|