Scrolling through memrec ddlist options

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
User avatar
gibberishh
Table Makers
Table Makers
Posts: 331
Joined: Fri Jul 02, 2021 5:48 pm
Reputation: 225

Scrolling through memrec ddlist options

Post by gibberishh »

Not sure if this has already been done previously, but here's code that allows you to setup hotkeys to scroll through a dropdown list's options. This is useless for memrecs that can increase/decrease by a fixed amount, but is great if your list is not contiguous. E.g., if your list is 1,2,4,5,6 because item 3 crashes the game, using a hotkey to inc/dec the value by 1 will not skip 3. This code will actually go through your ddlist items and select the next or previous option from the list, not from the value.

Place it in your table's Lua script.

Code: Select all

function ShiftSelection(ddrec,dir)
  ddrec = getAddressList().getMemoryRecordByDescription(ddrec)
  local allVals = ddrec.DropDownValue
  local itemCount = ddrec.DropDownCount
  local nextVal = (dir > 0) and allVals[0] or allVals[itemCount-1]
  for i=0,itemCount-1 do
    if allVals[i] == ddrec.Value then
      if dir > 0 then
        nextVal = (i < itemCount-dir) and allVals[i+dir] or nextVal
        break
      else
        nextVal = (i >= 0-dir) and allVals[i+dir] or nextVal
        break
      end
    end
  end
  return nextVal
end
To use, set up your hotkeys this way:
(To select next item) Set value to: [ShiftSelection("memrec description",1)]
(To select previous item) Set value to: [ShiftSelection("memrec description",-1)]

memrec description has to be an exact match to the label you've assigned to that memory record. Unfortunately {MRDescription} is not accessible to the Set value field, at least in CE 7.2, even though it is accessible to the Speech text field. :x

Post Reply

Who is online

Users browsing this forum: No registered users