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 


How to read/write in the combobox?

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

Joined: 17 Jan 2018
Posts: 202

PostPosted: Wed Mar 14, 2018 8:54 am    Post subject: How to read/write in the combobox? Reply with quote

How to read from address to CEComboBox1? For example:
3 items in the CEComboBox1:
None
Sadness
Fury

If value in the address == 0x00, then first item "None" must be selected.
If value in the address == 0x10, then second item "Sadness" must be selected.
If value in the address == 0x20, then third item "Fury" must be selected.

Second question: How to write to address from CEComboBox1? For example:
If first item "None" selected in the CEComboBox1, then write value 0x00 to the address.
If second item "Sadness" selected in the CEComboBox1, then write value 0x10 to the address.
If third item "Fury" selected in the CEComboBox1, then write value 0x20 to the address.
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Wed Mar 14, 2018 1:40 pm    Post subject: Reply with quote

something like

Code:
-- create for example
UDF1 = CreateForm()
CEComboBox1 = createComboBox(UDF1)
CEComboBox1.clear()
CEComboBox1.Items.Add('None')
CEComboBox1.Items.Add('Sadness')
CEComboBox1.Items.Add('Fury')
-- prepend formname. for non-code generated forms
-- eg CETrainer.CEComboBox1...

local addr = 0x400290

-- reads once, need in timer if you want to continuously read
local val = readInteger(addr)
if val == 0 then
  CEComboBox1.ItemIndex = 0
elseif val == 0x10 then
  CEComboBox1.ItemIndex = 1
else
  CEComboBox1.ItemIndex = 2
end

-- setup event handler to write whenever combobox changes
CEComboBox1.OnChange = function(sender)
  local values = {[0]=0, [1]=0x10, [2]=0x20}
  --fullAccess(addr,4) -- if readonly, make writable
  writeInteger(addr, values[sender.ItemIndex])
  -- more generically, works for any type not just 4 byte
  --getAddressList().getMemoryRecordByDescription('the desc.').Value = values[sender.ItemIndex]
end

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 202

PostPosted: Wed Mar 14, 2018 3:30 pm    Post subject: Reply with quote

FreeER wrote:
something like


If write, whenever combobox changes, by method:
Code:
UDF1.CEComboBox1.onChange = function(sender)
  local _value = { 0x00, 0x10, 0x20 }
  writeInteger('addr',_value[sender.ItemIndex])
end

Then, how to read by similar method? Without using "If" and with using table "local _value = { 0x00, 0x10, 0x20 }".
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Wed Mar 14, 2018 6:54 pm    Post subject: Reply with quote

To constantly read from the address and update the combobox you'd need a timer (or use the OnGetDisplayValue "event" on a memory record but without a memory record that's not an option) eg.

Code:
local t = createTimer()
t.Interval = 100 -- 1/10th of a second
t.OnTimer = function(timer)
  --need in timer if you want to continuously read
  local val = readInteger(addr)
  if val == 0 then
    CEComboBox1.ItemIndex = 0
  elseif val == 0x10 then
    CEComboBox1.ItemIndex = 1
  else
    CEComboBox1.ItemIndex = 2
  end
end


Though you could also use a table there eg.
Code:
local values = {[0x0]=0, [0x10]=1, [0x20]=2}
-- defaults to last if not in table
CEComboBox1.ItemIndex = values[val] or CEComboBox1.Items.Count-1


Though with these specific value you could also simply divide by 0x10

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 202

PostPosted: Thu Mar 15, 2018 10:44 am    Post subject: Reply with quote

Thanks for the help.
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