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 


Checklistbox: OnItemClick fn does not get saved/accepted

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 193

PostPosted: Sun May 18, 2025 10:47 am    Post subject: Checklistbox: OnItemClick fn does not get saved/accepted Reply with quote

image: see here [ https://ibb.co/album/NdwCkt ]

I can't seem to assign a function to 'OnItemClick': as soon as i leave the field, it gets removed.
Note: i currently solve it by parkouring the complete list, and find the 'Selected' in question

ps: tried all CE vs up to 7.5
ps2: i assume that this particular event 'kicks in' the moment one clicks on any list_entry (which gets then selected in the process). Ie clicking on any other location within the listbox (incl checkboxes) has no effect (iow the fn will then not be called) ?!
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 35

Joined: 16 Feb 2017
Posts: 1481

PostPosted: Sun May 18, 2025 5:37 pm    Post subject: Reply with quote

Here's an idea;

Code:
-- Destroy existing form if it exists
if myForm then myForm.Destroy() myForm=nil end

-- Create a new form
myForm = createForm()
myForm.Caption = "Select Line: ..."
myForm.Width = 300
myForm.Height = 400

-- Create a CheckListBox inside the form
checkListBox = createCheckListBox(myForm)
checkListBox.Width = 250
checkListBox.Height = 200
checkListBox.Left = 25
checkListBox.Top = 50

-- Add items to CheckListBox
for i = 0, 3 do
    checkListBox.Items.add("Item " .. i)
end

----------------------------------------

-- Functions to handle selection changes
function OnChange_d0(stt)
  if stt==1 then print(stt, "Hack ON!") else print(stt, "Hack OFF!") end
end

function OnChange_d1(stt)
  if stt==1 then print(stt, "Hack ON!") else print(stt, "Hack OFF!") end
end

function OnChange_d2(stt)
  if stt==1 then print(stt, "Hack ON!") else print(stt, "Hack OFF!") end
end

function OnChange_d3(stt)
  if stt==1 then print("Hack ON!") else print("Hack OFF!") end
end

local opts = 0 -- Option variable to manage click behavior

-- Function to handle selection changes based on click type
function onSelectionChange(sender)
    local index = sender.ItemIndex
    if index >= 0 then
        -- If checkbox is clicked, maintain its state
        if opts == 1 then
           sender.Checked[index] = sender.Checked[index]
        else
            -- If item text is clicked, toggle checkbox state
            sender.Checked[index] = not sender.Checked[index]
        end

        -- Call corresponding OnChange_d function
        local rn = _G["OnChange_d" .. index]
        local isState = sender.Checked[index] and 1 or 0 or nil
        rn(tonumber(isState))
    end
    opts = 0 -- Reset option variable
end

-- Triggered only when clicking on the checkbox
checkListBox.OnClickCheck = function(s) opts=1 onSelectionChange(s) end

-- Triggered only when clicking on the item text, does not affect checkbox
checkListBox.OnClick = function(s) if opts~=1 then onSelectionChange(s) end end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website MSN Messenger
paul44
Expert Cheater
Reputation: 2

Joined: 20 Jul 2017
Posts: 193

PostPosted: Wed May 21, 2025 11:48 am    Post subject: Reply with quote

@AylinCE: thx for that code; i will try '.OnClick' probably this weekend; and report back...
(problem w/ checkListBox, is no/minimal info; let alone about them event_functions)
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 35

Joined: 16 Feb 2017
Posts: 1481

PostPosted: Thu May 22, 2025 11:17 am    Post subject: Reply with quote

I think it depends on the frequency of use; It is a control left to the Supply - Demand option.

On the other hand, the "OnClick" event alone would be an insufficient solution.
OnClick only makes selections in the row and works independently of the box marking. (This would be like a normal "ListBox".)
"OnClickCheck", on the other hand, only follows the box marking or unmarking.
If both events are used, "OnClick" will return the valid result.
The code above uses both events without any problems.


You can add a row or something else to "rn(tonumber(isState))" and send it to the function.


Remember; In cases where a selection does not affect the other selections (If multiple selections can be made), it can be used in "ScrollBar" and "CheckBox" in it.

However, depending on the necessity, the decision is yours.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
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 Visit poster's website 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