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 


Cheat Engine Forum Index
PostGo back to topic
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011
Posts: 1066
Location: 0x90

PostPosted: Tue Nov 07, 2023 12:00 pm    Post subject:

bknight2602 wrote:
I made an error in the first post, so your post makes sense There are 5 items in the Radiogroup, which I'm trying to select the last one with 4, but the error still exits. I have tried other methods like .SetItemIndex(4) also doesn't work, but I forgot the error type.


It's a little unclear exactly what you require. Is it the last item in the radiogroup whose caption contains the number 4? If so clarify so that I can modify the code.

This code will demonstrate how to select the last item but one in a radiogroup.
Code:

if f then f.destroy(); f = nil end
f = createForm(getMainForm())
f.Name = 'frmMain'
f.Caption = 'Main Form'
f.Width = 300
f.Height = 275
f.centerScreen()
--------------------------------
local rg = createRadioGroup(f)
rg.Align = 'alTop'
rg.Name = 'rg'
rg.Height = f.Height - 30
rg.Caption = 'Select Item'
rg.Columns = 2
rg.OnClick = function(sender)
               -- Set the form's caption to the selected index of the radio group.
               -- We add 1 to the ItemIndex because radiogroup's item objects are 0-based.
               f.Caption = 'Selected Index: ' .. tostring(sender.ItemIndex+1)
             end


local function init()
   -- Create a temporary StringList to store the values for the radiogroup.
   local sl = createStringList(f)
   -- Let's loop through and create 10-items and add them to the StringList.
   for i = 1, 10 do
      sl.add('Item ' .. tostring(i))
   end
   -- Assign the radiogroup's items to those of the StringList.
   rg.Items = sl
   -- Finally, free the StringList because it's no longer needed.
   sl.destroy()
 end

local btn = createButton(f)
btn.Align = 'alBottom'
btn.Name = 'btnSelect'
btn.Height = 30
btn.Caption = 'Click'
btn.OnClick = function()
                -- StringList item components are 0-based, meaning the first item is at index 0.
                -- So we subtract 1 from the total count to get the correct count.
                local count = rg.Items.Count - 1
                -- Finally, set the ItemIndex of the radiogroup to the total count minus one.
                rg.ItemIndex = count - 1
              end

-- Lastly, execute the init function.
init()


I have commented lines for clarification.
Back to top
View user's profile Send private message
Post reviews:   Approve 1
Author Review
++METHOS
Review: Approve
Post reference:
ReviewPosted: Fri Nov 10, 2023 9:30 am

For helping others.
Back to top
View user's profile Send private message
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites