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 


After create the hotkey how bound it
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials
View previous topic :: View next topic  
Author Message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Fri Mar 06, 2020 9:19 am    Post subject: After create the hotkey how bound it Reply with quote

after i do createHotkey(CECheckbox1(),VK_P,VK_C) how i can make the checkbox with the hotkey boundable ?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 83

Joined: 06 Jul 2014
Posts: 2779

PostPosted: Fri Mar 06, 2020 11:23 am    Post subject: Reply with quote

Do you mean how to make it do something?
Code:
function toggle_checkbox(cb)
  cb.Checked = not cb.Checked
end

createHotkey(toggle_checkbox, key1, key2, key3, ...)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Fri Mar 06, 2020 11:35 am    Post subject: Reply with quote

i got Error:attempt to call a nil value
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 35

Joined: 01 Oct 2008
Posts: 836

PostPosted: Fri Mar 06, 2020 2:12 pm    Post subject: Reply with quote

It may bind an object (the checkbox) to a function, to create a new function provided for createHotkey, like this

Code:

function bind1(fn,o)return function(...) return fn(o,...) end end

function toggle_checkbox(cb, hko)
  cb.Checked = not cb.Checked
  if hko then -- optional, hko can be omit in function argument list
--    ... do stuff specific for hotkey object if need
  end
end

createHotkey(bind1(toggle_checkbox,  cb_the_check_box_object    ), key1, key2, key3, ...)

_________________
- Retarded.
Back to top
View user's profile Send private message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Fri Mar 06, 2020 2:58 pm    Post subject: Reply with quote

I am a beginner can you send me an .exe with the code so that I can see more clearly
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 35

Joined: 01 Oct 2008
Posts: 836

PostPosted: Fri Mar 06, 2020 3:03 pm    Post subject: Reply with quote

This an example on an Edit control.

1. create a Form named UDF1, create 2 Edit named CEEdit1 and CEEdit2
2. Assign both Edit OnChange event function to HexOnChange
3. Add following script

Code:

function bind1(fn,o)return function(...) return fn(o,...) end end

function HexOnChange(me, hko)
  if not tonumber(me.Text,16)then me.Text = '0' end--normalize hex text
-- hko stuff start
  local v, hkAction = tonumber(me.Text,16)
  if hko==INC1 or hko==RIGHT1 then
    v,hkAction = v+1,'INC'
  elseif hko==DEC1 or hko==LEFT1 then
    v,hkAction = v-1,'DEC'
  end
  -- update possible change from hko
  me.Text = v >= 0 and string.format("%X",v) or string.format("-%X",-v)
-- hko stuff end

  -- do response on change --
  GetMainForm().Caption = (hkAction or 'normal')..' '..me.Text..' on '..me.Name

end

-- bind UDF1.CEEdit1 to HexOnChange
local bound1 = bind1(HexOnChange, UDF1.CEEdit1)
if INC1 then INC1=nil,INC1.Destroy()end
INC1 = createHotkey(bound1, VK_UP, VK_LSHIFT, VK_LCONTROL)
if DEC1 then DEC1=nil,DEC1.Destroy()end
DEC1 = createHotkey(bound1, VK_DOWN, VK_LSHIFT, VK_LCONTROL)

-- bind UDF1.CEEdit2 to HexOnChange
local bound2 = bind1(HexOnChange, UDF1.CEEdit2)
if RIGHT1 then RIGHT1=nil,RIGHT1.Destroy()end
RIGHT1 = createHotkey(bound2, VK_RIGHT, VK_LSHIFT, VK_LCONTROL)
if LEFT1 then LEFT1=nil,LEFT1.Destroy()end
LEFT1 = createHotkey(bound2, VK_LEFT, VK_LSHIFT, VK_LCONTROL)

UDF1.Show()

_________________
- Retarded.


Last edited by panraven on Fri Mar 06, 2020 3:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Fri Mar 06, 2020 3:13 pm    Post subject: Reply with quote

i got this
Error:[string "..."]:5: bad argument #1 to 'tonumber' (string expected, got nil)
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 35

Joined: 01 Oct 2008
Posts: 836

PostPosted: Fri Mar 06, 2020 3:23 pm    Post subject: Reply with quote

dport80 wrote:
i got this
Error:[string "..."]:5: bad argument #1 to 'tonumber' (string expected, got nil)


My example use an Edit control, which has .Text property.
CheckBox does not has .Text property.

May paste your script?
Also check the ui/function names match.

_________________
- Retarded.
Back to top
View user's profile Send private message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Fri Mar 06, 2020 4:03 pm    Post subject: Reply with quote

Code:
function bind1(fn,o)return function(...) return fn(o,...) end end

function CETrainer_CECheckbox1Change(me, hko)
  if not tonumber(me.Checked)then me.Checked = true end--normalize hex text
local v, hkAction = tonumber(me.Checked)
  if hko==INC1 or hko==RIGHT1 then
    v,hkAction = true, 'INC1'
  elseif hko==DEC1 or hko==LEFT1 then
    v,hkAction = false,'DEC'
  end
end

-- new function binding the CEEdit1 to UDF1_CEEdit1Change as hotkey handler


-- define hotkeys
local bound1 = bind1(CECheckbox1Change, CETrainer.CECheckbox1)
if INC1 then INC1=nil,INC1.Destroy()end
INC1 = createHotkey(bound1, VK_UP, VK_LSHIFT, VK_LCONTROL)
if DEC1 then DEC1=nil,DEC1.Destroy()end
DEC1 = createHotkey(bound1, VK_DOWN, VK_LSHIFT, VK_LCONTROL)


local bound2 = bind1(CECheckbox1Change, CETrainer.CECheckbox1)
if RIGHT1 then RIGHT1=nil,RIGHT1.Destroy()end
RIGHT1 = createHotkey(bound2, VK_RIGHT, VK_LSHIFT, VK_LCONTROL)
if LEFT1 then LEFT1=nil,LEFT1.Destroy()end
LEFT1 = createHotkey(bound2, VK_LEFT, VK_LSHIFT, VK_LCONTROL)

CETrainer.Show()


When i execute keybind that do that error
`Error:[string "..."]:2: attempt to call a nil value (upvalue 'fn')`
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 35

Joined: 01 Oct 2008
Posts: 836

PostPosted: Fri Mar 06, 2020 4:30 pm    Post subject: Reply with quote

dport80 wrote:

--code
...
function CETrainer_CECheckbox1Change(me, hko)
-- tonumber not need for check box
-- if not tonumber(me.Checked)then me.Checked = true end--normalize hex text
local v, hkAction = me.Checked -- remove tonumber
if hko==INC1 or hko==RIGHT1 then
v,hkAction = true, 'INC1'
elseif hko==DEC1 or hko==LEFT1 then
v,hkAction = false,'DEC'
end

-- update change
me.Checked = v

end

-- new function binding the CEEdit1 to UDF1_CEEdit1Change as hotkey handler


-- define hotkeys
local bound1 = bind1(CECheckbox1Change, CETrainer.CECheckbox1)...
...
--/code

When i execute keybind that do that error
`Error:[string "..."]:2: attempt to call a nil value (upvalue 'fn')`


Check the names?
Also check the event handler assigned in ui designer is matching.

_________________
- Retarded.
Back to top
View user's profile Send private message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Fri Mar 06, 2020 5:06 pm    Post subject: Reply with quote

Code:
function CETrainer_CECheckbox1Change(me, hko)
  if not tonumber(me.Checked)then me.Checked = true end--normalize hex text
local v, hkAction = tonumber(me.Checked)
  if hko==INC1 or hko==RIGHT1 then
    v,hkAction = true, 'INC1'
  elseif hko==DEC1 or hko==LEFT1 then
    v,hkAction = false,'DEC1'
  end
end

-- new function binding the CEEdit1 to UDF1_CEEdit1Change as hotkey handler


-- define hotkeys
local bound1 = bind1(CECheckbox1Change, CETrainer.CECheckbox1)
if INC1 then INC1=nil,INC1.Destroy()end
INC1 = createHotkey(bound1, VK_C)
if DEC1 then DEC1=nil,DEC1.Destroy()end
DEC1 = createHotkey(bound1, VK_C)


local bound2 = bind1(CECheckbox1Change, CETrainer.CECheckbox1)
if RIGHT1 then RIGHT1=nil,RIGHT1.Destroy()end
RIGHT1 = createHotkey(bound2, VK_C)
if LEFT1 then LEFT1=nil,LEFT1.Destroy()end
LEFT1 = createHotkey(bound2, VK_O)

CETrainer.Show()

the hotkey not work and name match, and event i only have on Checkbox Event bind1 to OnChange
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 35

Joined: 01 Oct 2008
Posts: 836

PostPosted: Fri Mar 06, 2020 6:13 pm    Post subject: Reply with quote

Sorry, I've an exceptional talent to complicate simple thing Smile

Your script in another topic probably almost work (if name matched, ie.CECheckbox1 -> CECheckbox1Change).
Code:

function CECheckbox1Change(sender)
  CETrainer.CECheckbox1.Checked = not CETrainer.CECheckbox1.Checked
end
createHotkey(CECheckbox1Change,VK_C)


Anyway to continue our complicated investigation ...

1. Check that CETrainer_CECheckbox1Change is not the same as CECheckbox1Change. character '_' in lua is same as 'a'..'z' as part of a variable naming;
2. My example is to make a function to do 4 different thing with 4 different hotkey, if some of the key combo are the same, they may undo one another;
3. Some previous hotkey function defined has not been destroy, which may interrupt or change the current hotkey behaviour. Try save the CT then close the ce and restart it to remove unwanted hotkey function.

_________________
- Retarded.


Last edited by panraven on Sat Mar 07, 2020 5:48 am; edited 1 time in total
Back to top
View user's profile Send private message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Sat Mar 07, 2020 3:35 am    Post subject: Reply with quote

i got that :
Error:[string "function CECheckbox1Change(sender)..."]:2: attempt to index a nil value (global 'CECheckbox1')
Code:
function CECheckbox1Change(sender)
local state = CECheckbox1 getState(CECheckbox1.Checked)
setProperty(CECheckbox1, "checked", true or false)


end
createHotkey(CECheckbox1Change,VK_P)
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 35

Joined: 01 Oct 2008
Posts: 836

PostPosted: Sat Mar 07, 2020 5:51 am    Post subject: Reply with quote

dport80 wrote:
i got that :
Error:[string "function CECheckbox1Change(sender)..."]:2: attempt to index a nil value (global 'CECheckbox1')
Code:
function CECheckbox1Change(sender)
local state = CECheckbox1 getState(CECheckbox1.Checked)
setProperty(CECheckbox1, "checked", true or false)


end
createHotkey(CECheckbox1Change,VK_P)


Need this change?
CECheckbox1 -> CETrainer.CECheckbox1
Code:

function CECheckbox1Change(sender)
  CETrainer.CECheckbox1.Checked = not CETrainer.CECheckbox1.Checked
end
createHotkey(CECheckbox1Change,VK_C)

_________________
- Retarded.
Back to top
View user's profile Send private message
dport80
Newbie cheater
Reputation: 0

Joined: 06 Mar 2020
Posts: 12

PostPosted: Sat Mar 07, 2020 6:32 am    Post subject: Reply with quote

Thank you for being patient to help me

Error:[string "function CECheckbox1Change(sender)..."]:2: C stack overflow

i got that when i bound it while im on generated trainer but it work while im on
go back to generated trainer

Code:

function CECheckbox1Change(sender)
   CETrainer.CECheckbox1.Checked = not CETrainer.CECheckbox1.Checked
end
createHotkey(CECheckbox1Change,VK_C)
createHotkey(CECheckbox1Change,VK_O)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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