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 


Cycle through list options with hotkey

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials
View previous topic :: View next topic  
Author Message
gibberishh
Cheater
Reputation: 1

Joined: 30 Aug 2021
Posts: 45

PostPosted: Sun Jul 17, 2022 9:49 pm    Post subject: Cycle through list options with hotkey Reply with quote

Dark Byte has previously provided a tutorial on how to toggle bit values on hotkey using [value~1] as the value to set.

Here is a very simply way to cycle through a list of options, which I think is a much more common scenario:
Hotkey: Enter your selected hotkey/combo.
On Hotkey: Set Value To
Value: [(value < 259) and (value + 1) or 0]

In this example, 259 is the maximum number of items in the dropdown list, 0 is the first item, and values are being incremented by 1.

Technically that explanation is incorrect. 259 is the maximum allowable value for the field and 0 is the lowest. One can use this kind of hotkey setup even if you don't have a dropdown list. If the current value is 259, the hotkey will automatically cycle back to 0 without having to write a script to do so. You can have another hotkey to decrement values in a similar way.

Anything within square brackets is interpreted as Lua code so, within certain limitations, one can take this basic concept quite far with hotkeys.

If you are new to CE, note that memrecs always work with the actual value. It does not matter whether your dropdown list displays values and/or only descriptive text. Memrecs don't care about what the dropdown list displays. You are always working with the underlying value which is usually a number.

For those coming from other programming backgrounds, the 'and -- or' setup here works exactly like the (condition ? if-true : if-false) scenario in some other languages.

_________________
It's not cheating. It's playing by my rules.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 147

Joined: 06 Jul 2014
Posts: 4570

PostPosted: Sun Jul 17, 2022 10:30 pm    Post subject: Reply with quote

Modular arithmetic is another way of getting this same behaviour. i.e. `[(value + 1) % 260]`
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
gibberishh
Cheater
Reputation: 1

Joined: 30 Aug 2021
Posts: 45

PostPosted: Sun Jul 17, 2022 11:33 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Modular arithmetic is another way of getting this same behaviour. i.e. `[(value + 1) % 260]`

Nice. Didn't think of that. The conditional formula is probably easier for people to read and interpret though.
-------------
Forgot to mention that this only works if all your list items are equidistant -- in these examples, the distance is 1. But maybe you have a list that is 0,4,8,12,16,etc. You will want to increment values by 4, but the formula will still work. In fact, any mathematical formula which will let you reach the next item will work. So maybe your distance isn't just a plain old +1 or +4. Maybe it's value*(1+value).

However, let's say you determine that Item 12 is buggy and causes the game to crash. So you remove that option from the dropdown list. The formula will still put in 12 after 8. It won't jump to 16. The hotkey is not actually cycling through the dropdown options, it is only increasing/decreasing the actual value of the memory record.

_________________
It's not cheating. It's playing by my rules.
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 Tutorials 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