View previous topic :: View next topic |
Author |
Message |
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
Posted: Tue May 19, 2020 12:29 pm Post subject: Simulating activation of registered code(How is Execute code |
|
|
To get started, there is a representative code below.
I want to read and activate the code written in the memo box.
It should probably read and activate a timer.
How is this done?
Code: | UDF1.CETimer1.Enabled=false
UDF1.CETimer2.Enabled=false
UDF1.CETimer1.Interval=1
UDF1.CETimer2.Interval=1
local tIndex=0
function UDF1_CETimer1Timer(sender)
tIndex=tonumber(tIndex) + 1
end
function UDF1_CETimer2Timer(sender)
if UDF1.CEMemo1.Lines.Text=="" then
showMessage("Registered code not found!\nPlease save the code first.")
tIndex=tonumber(tIndex) + 1
-- Execute Code=UDF1.CEMemo1.Lines.Text?
end
-------------------------------------------------------
function UDF1_CEPanel2Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel7Click() end")
end
function UDF1_CEPanel3Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel8Click() end")
end
function UDF1_CEPanel4Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel9Click() end")
end
function UDF1_CEPanel5Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel10Click() end")
end
function UDF1_CEPanel6Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel11Click() end")
end
-------------------------------------------------------
function UDF1_CEPanel7Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel7Click")
end
function UDF1_CEPanel8Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel8Click")
end
function UDF1_CEPanel9Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel9Click")
end
function UDF1_CEPanel10Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel10Click")
end
function UDF1_CEPanel11Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel11Click")
end
-------------------------------------------------------
function UDF1_CECheckbox1Change(sender)
if UDF1.CECheckbox1.checked==true then
tIndex=0
UDF1.CEMemo1.Lines.Text=""
UDF1.CEMemo1.Lines.Add("function Play1()")
UDF1.CETimer1.Enabled=true
else
UDF1.CETimer1.Enabled=false
UDF1.CEMemo1.Lines.Add("end")
end
end
function UDF1_CECheckbox2Change(sender)
if UDF1.CECheckbox2.checked==true then
tIndex=0
UDF1.CEMemo2.Lines.Text=""
UDF1.CETimer2.Enabled=true
else
UDF1.CETimer2.Enabled=false
end
end |
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Tue May 19, 2020 3:23 pm Post subject: |
|
|
If I am not misunderstood, you ask about 'How to execute codes writing in a memo'. Use loadstring(code)(), while code is memo lines text.
Example:
Code: | script = [[
f = createForm()
b = createButton(f)
b.Caption = 'Click Me'
function bclick()
print('Hello world')
end
b.OnClick = bclick
]]
UDF1.CEMemo1.Clear()
function runScriptFromMemoContents(code)
UDF1.CEMemo1.Clear()
UDF1.CEMemo1.Lines.Text = script
code = UDF1.CEMemo1.Lines.Text
if code == "" then showMessage('Nothing to execute') else
loadstring(code)()
end
end
UDF1.Show()
UDF1.CEButton1.OnClick = runScriptFromMemoContents |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
Posted: Tue May 19, 2020 5:03 pm Post subject: |
|
|
In addition to the above code;
Code: | UDF1.CEMemo1.Lines.Text=([[
function play1()
if tIndex==110 then
UDF1_CEPanel7Click() end
if tIndex==153 then
UDF1_CEPanel8Click() end
if tIndex==207 then
UDF1_CEPanel9Click() end
if tIndex==255 then
UDF1_CEPanel10Click() end
if tIndex==308 then
UDF1_CEPanel11Click() end
if tIndex==394 then
UDF1_CEPanel11Click() end
if tIndex==445 then
UDF1_CEPanel10Click() end
end
]])
function UDF1_CETimer2Timer(sender)
if UDF1.CEMemo1.Lines.Text=="" then
showMessage("Registered code not found!\nPlease save the code first.")
else
tIndex=tonumber(tIndex) + 1
examp2 = UDF1.CEMemo1.Lines.Text
loadstring(examp2)()
play1()
end
end
local path = TrainerOrigin
print(path)
function CodeSave() --Memo1
local index = 1
if path then
local settingsFile = io.open(path.."Example.txt", "w")
if (settingsFile ~= nil) then
settingsFile:write(control_getCaption(UDF1.CEMemo1))
settingsFile:close()
end
end
end
function CodeLoad() --Memo1
if path then
local settingsFile = io.open(path.."Example.txt", "r")
if (settingsFile ~= nil) then
UDF1.CEMemo1.Lines.Text = settingsFile:read("*a")
settingsFile:close()
end
end
end
function UDF1_CECheckbox2Change(sender)
if sender.checked==true then
tIndex=0
UDF1.CEMemo2.Lines.Text=""
UDF1.CETimer2.Enabled=true
else
UDF1.CETimer2.Enabled=false
end
end |
How can I run "play1 ()" or "Memo1" commands.
I tried the method you gave me did not work.
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Tue May 19, 2020 9:43 pm Post subject: |
|
|
Code: | function UDF1_CETimer2Timer(sender)
if UDF1.CEMemo1.Lines.Text=="" then
showMessage("Registered code not found!\nPlease save the code first.")
else
tIndex=tonumber(tIndex) + 1
examp2 = UDF1.CEMemo1.Lines.Text
loadstring(examp2) (play1) --- looking here
play1()
end
end |
Similar with this code:
Code: | UDF1.CEMemo1.Lines.Text=[[
function play1()
print('hello world')
end
]]
function test()
local examp2 = UDF1.CEMemo1.Lines.Text
loadstring(examp2) (play1)
play1()
end
UDF1.Show()
UDF1.CEButton1.OnClick = test
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
Posted: Wed May 20, 2020 9:08 am Post subject: |
|
|
Solved @Corroder.
Key point; Write the entire function into Load.
Example;
Code: | examp11=[[
local tIndex=0 --It doesn't work to promote it in lua. It is necessary to introduce it in Load.
function Play1()
print(tIndex)
if tIndex==tonumber(120) then
UDF1_CEPanel7Click() end
if tIndex==163 then
UDF1_CEPanel8Click() end
if tIndex==202 then
UDF1_CEPanel9Click() end
if tIndex==237 then
UDF1_CEPanel10Click() end
if tIndex==284 then
UDF1_CEPanel11Click() end
if tIndex==430 then
UDF1_CEPanel10Click() end
if tIndex==482 then
UDF1_CEPanel9Click() end
if tIndex==521 then
UDF1_CEPanel8Click() end
if tIndex==577 then
UDF1_CEPanel7Click() end
if tIndex==678 then
UDF1_CEPanel7Click() end
if tIndex==723 then
UDF1_CEPanel7Click() end
if tIndex==777 then
UDF1_CEPanel8Click() end
if tIndex==818 then
UDF1_CEPanel8Click() end
if tIndex==867 then
UDF1_CEPanel9Click() end
if tIndex==908 then
UDF1_CEPanel9Click() end
if tIndex==956 then
UDF1_CEPanel10Click() end
if tIndex==1001 then
UDF1_CEPanel10Click() end
if tIndex==1071 then
UDF1_CEPanel11Click() end
if tIndex==1113 then
UDF1_CEPanel11Click() end
if tIndex==1168 then
UDF1_CEPanel7Click() end
if tIndex==1288 then
UDF1.CETimer2.Enabled=false
end
end
UDF1.CETimer2.OnTimer=function()
tIndex=tonumber(tIndex) + 1
Play1()
end
]]
--Save
function UDF1_CECheckbox1Change(sender)
if UDF1.CECheckbox1.checked==true then
tIndex=0
UDF1.CEMemo1.Lines.Text=""
UDF1.CEMemo1.Lines.Add("local tIndex=0")
UDF1.CEMemo1.Lines.Add("function Play1()")
UDF1.CETimer1.Enabled=true
else
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1.CETimer2.Enabled=false")
UDF1.CEMemo1.Lines.Add("end")
UDF1.CEMemo1.Lines.Add("end")
UDF1.CEMemo1.Lines.Add("\nUDF1.CETimer2.OnTimer=function()")
UDF1.CEMemo1.Lines.Add("tIndex=tonumber(tIndex) + 1")
UDF1.CEMemo1.Lines.Add("Play1()")
UDF1.CEMemo1.Lines.Add("end")
CodeSave()
UDF1.CETimer1.Enabled=false
end
end
--Load and Play
function UDF1_CECheckbox2Change(sender)
UDF1.CEMemo2.Lines.Text=""
local examp2 = UDF1.CEMemo1.Lines.Text
if sender.checked==true then
examp12=([[]]..UDF1.CEMemo1.Lines.Text..[[]])
load(examp12)()
UDF1.CETimer2.Enabled=true
else
UDF1.CETimer2.Enabled=false
end
end |
And Thanks Again.
( Imagine doing a Piano with CE Lua.
It should have 8 notes and 8 effects.
The above question is; It simulates recording music and automatic replay.
I think my project is complete. )
_________________
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
|
Back to top |
|
|
|