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 


proper syntax

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 582

PostPosted: Sun Nov 05, 2023 3:29 pm    Post subject: proper syntax Reply with quote

I'm ryingto set the index of a radiogroup to the last of four itiems
Code:

trainer.characters_rg.ItemIndex = 4;


This gives me an error Error:Invalid class object
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 468

Joined: 09 May 2003
Posts: 25706
Location: The netherlands

PostPosted: Mon Nov 06, 2023 12:25 am    Post subject: Reply with quote

index starts at 0 for internal GUI stuff. So if there are 4 items, the last one has index 3
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 582

PostPosted: Tue Nov 07, 2023 11:17 am    Post subject: Reply with quote

Dark Byte wrote:
index starts at 0 for internal GUI stuff. So if there are 4 items, the last one has index 3

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.
Back to top
View user's profile Send private message Yahoo Messenger
Dark Byte
Site Admin
Reputation: 468

Joined: 09 May 2003
Posts: 25706
Location: The netherlands

PostPosted: Tue Nov 07, 2023 11:52 am    Post subject: Reply with quote

maybe the path trainer.characters_rg is invalid
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1066
Location: 0x90

PostPosted: Tue Nov 07, 2023 12:00 pm    Post subject: This post has 1 review(s) Reply with quote

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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 582

PostPosted: Tue Nov 07, 2023 12:17 pm    Post subject: Reply with quote

I opened a blank CE and inserted
Code:

function selectradiogroup()
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()
end

Does not create a a form or radiogroup, so executing init() seems like it won't work.
My request is simple what is the syntax for the radiogroup I have, to select the last radio. I posted the command that I use and it generates an error.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 35

Joined: 16 Feb 2017
Posts: 1478

PostPosted: Tue Nov 07, 2023 12:23 pm    Post subject: Reply with quote

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)
               f.Caption = 'Selected Index: ' .. tostring(sender.ItemIndex)
             end

local function init()
   local sl = createStringList(f)
   for i = 0, 4 do
    if i==0 then
      sl.add('None ' .. tostring(i))
    else
      sl.add('Item ' .. tostring(i))
    end
   end
   rg.Items = sl
   sl.destroy()
 end

local btn = createButton(f)
btn.Align = 'alBottom'
btn.Name = 'btnSelect'
btn.Height = 30
btn.Caption = 'Click'
btn.OnClick = function()
                local count = rg.Items.Count -1
                rg.ItemIndex = 4 -- There are 5 items in the radio group, I'm trying to select the last one with 4
                 --btn.Caption = 'Click '..count.." //  Index:  "..rg.ItemIndex
              end

init()

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 582

PostPosted: Tue Nov 07, 2023 12:39 pm    Post subject: Reply with quote

AylinCE wrote:
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)
               f.Caption = 'Selected Index: ' .. tostring(sender.ItemIndex)
             end

local function init()
   local sl = createStringList(f)
   for i = 0, 4 do
    if i==0 then
      sl.add('None ' .. tostring(i))
    else
      sl.add('Item ' .. tostring(i))
    end
   end
   rg.Items = sl
   sl.destroy()
 end

local btn = createButton(f)
btn.Align = 'alBottom'
btn.Name = 'btnSelect'
btn.Height = 30
btn.Caption = 'Click'
btn.OnClick = function()
                local count = rg.Items.Count -1
                rg.ItemIndex = 4 -- There are 5 items in the radio group, I'm trying to select the last one with 4
                 --btn.Caption = 'Click '..count.." //  Index:  "..rg.ItemIndex
              end

init()

I addd the fuction because the first time I tried it, error. However after deleting the funtion, I get a main form with 10 items, number nine is selected.
Now without a lot of code, what is the correct snytac to my initial question. The abovfe3 may answer for you but it doesn't answer to me, sorry.
trainer.characters_rg.ItemIndex = 4; = error. What does it need to be to select item 4 in the group?



2023-11-07_12-34-17.png
 Description:
 Filesize:  93.79 KB
 Viewed:  8387 Time(s)

2023-11-07_12-34-17.png


Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 35

Joined: 16 Feb 2017
Posts: 1478

PostPosted: Tue Nov 07, 2023 1:47 pm    Post subject: Reply with quote

Trainer Name or Gui Table name: trainer
RadioGroup Name: characters_rg
RadioGroup Gui name: trainer.characters_rg

RadioGroup items: 0,1,2,3,4 -- last: 4

Code:
rg = trainer.characters_rg
local count = rg.Items.Count -1 -- rg.Items.Count: 5, rg.Items.Count -1: 4
print(count) --> 4
rg.ItemIndex = count -- select  RadioGroup items: 4 (or tonumber(count))


characters table name: characters or trainer1.characters

characters table items: 1,2,3,4,5

Code:
rg = trainer.characters_rg
local count = rg.Items.Count -1 -- rg.Items.Count: 5, rg.Items.Count -1: 4
print(count) --> 4
rg.ItemIndex = count -- select  RadioGroup items: 4 (last)
local tableCount = tonumber(rg.ItemIndex) + 1
trainer1.characters[tableCount] -- select table items: 5 (last)

_________________
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
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 582

PostPosted: Tue Nov 07, 2023 2:27 pm    Post subject: Reply with quote

I give up.
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1066
Location: 0x90

PostPosted: Tue Nov 07, 2023 6:48 pm    Post subject: Reply with quote

bknight2602 wrote:
I give up.


I had asked for clarification of your request. It just seems like you want to select index 4. So whatever your radiogroup component is named use this:
Code:

my_radiogroup_component.ItemIndex = 3


As explained, indices used by the radiogroup are 0-based meaning that the first item is at index 0, the second item at index 1, the third item at index 2 and so on. If you take the time to read the comments and the code, perhaps you can understand it and learn from it.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 582

PostPosted: Sat Nov 11, 2023 5:24 pm    Post subject: Reply with quote

LeFiXER wrote:
bknight2602 wrote:
I give up.


I had asked for clarification of your request. It just seems like you want to select index 4. So whatever your radiogroup component is named use this:
Code:

my_radiogroup_component.ItemIndex = 3


As explained, indices used by the radiogroup are 0-based meaning that the first item is at index 0, the second item at index 1, the third item at index 2 and so on. If you take the time to read the comments and the code, perhaps you can understand it and learn from it.

Precisely what I wished. Thanks for the clear, concise answer that I already was using. With that I debugged other parts of the code and found the error, and trainer.characters_rg.ItemIndex = 4; was not the error.
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1066
Location: 0x90

PostPosted: Sun Nov 12, 2023 7:10 am    Post subject: Reply with quote

bknight2602 wrote:
Precisely what I wished. Thanks for the clear, concise answer that I already was using. With that I debugged other parts of the code and found the error, and trainer.characters_rg.ItemIndex = 4; was not the error.


What problem(s) are you having?
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 582

PostPosted: Sun Nov 12, 2023 7:59 am    Post subject: Reply with quote

LeFiXER wrote:
bknight2602 wrote:
Precisely what I wished. Thanks for the clear, concise answer that I already was using. With that I debugged other parts of the code and found the error, and trainer.characters_rg.ItemIndex = 4; was not the error.


What problem(s) are you having?

None at present, fixed the ones that errored starting this thread.
Back to top
View user's profile Send private message Yahoo Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Nov 12, 2023 7:18 pm    Post subject: Reply with quote

like this...

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()
--------------------------------

radioGroup = createRadioGroup(f)
radioGroup.Caption = 'Options'
radioGroup.Items.add('Option 1')
radioGroup.Items.add('Option 2')
radioGroup.Items.add('Option 3')
radioGroup.ItemIndex = -1

-- Function to execute when the value changes
function radioGroupSelectionChanged(Sender)
  ShowMessage('RadioGroup.Index: '..tostring(radioGroup.ItemIndex))
  if radioGroup.ItemIndex == 0 then ShowMessage('First item selected') end
  if radioGroup.ItemIndex == 1 then ShowMessage('Second item selected') end
  if radioGroup.ItemIndex == 2 then ShowMessage('Third item selected') end
end

-- Set the function to be executed on change
radioGroup.onSelectionChanged = radioGroupSelectionChanged



Then just set cheat for each rg item index on line '...if.....then....end'

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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 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