Post subject: Lua botting?
Samsara
She/They
Senior Judge, Site Admin, Expert player (2098)
Joined: 11/13/2006
Posts: 2821
Location: Northern California
I've always been fascinated with Lua bots used in other submissions, but with me being a super beginner in Lua and code-averse in general, I have no idea how to actually go about making one. Any tips or advice? Or should I just study some of the other bot scripts and go from there?
TASvideos Admin and acting Senior Judge 💙 Currently unable to dedicate a lot of time to the site, taking care of family. Now infrequently posting on Bluesky
warmCabin wrote:
You shouldn't need a degree in computer science to get into this hobby.
Editor, Expert player (2327)
Joined: 5/15/2007
Posts: 3927
Location: Germany
Hello and welcome to TASvideos. What kind of bot script would you like to do?
Post subject: Lua bots overview
Masterjun
He/Him
Site Developer, Skilled player (1986)
Joined: 10/12/2010
Posts: 1185
Location: Germany
Lua botting is a big topic. I'd like to give an overview. How hard it's going to be to make a bot depends on how complicated the things are you want to do. So my first piece of advice would be to imagine exactly what you want from this bot. Since you didn't really specify that, I'm just going to start from the easiest one. So what is the easiest Lua bot? A bot that displays a value on the screen? Probably not. We usually associate a Lua bot with something that changes or creates input. So to start off, you'd probably want to create a script that just holds a button (the Hello World! kind of program, if you will), and the best way to do that is, as you suggested, to study some of the other bot scripts. Of course this is too easy and not really useful in emulators that have an autohold feature. But now that you know the syntax on how to press buttons programmatically in Lua, you can easily write simple scripts that press a button every second or third frame (maybe while dealing with lag and also save the position with savestates), other input macros, or more complicated bots. Now, these are currently all bots that work in realtime by which I mean they don't use savestates to get additional information about future frames (and indeed, you can go quite far with those), but of course there are bots that create whole movies! Working input files! This is where we enter the more complicated bots. Before we go to the bots that create whole movies, we just look at savestate usage. Maybe you just want to brute force some RNG value. You just load a savestate, try the next set of input combinations, advance a bunch of frames, check if the value fits, if it does then you stop, if it doesn't start from the beginning. The reason I want to emphasize the frame advances is because that is exactly the point where it differs from the previous bots. It became nonlinear. You stopped calling the script each frame to display something or calculate the current inputs and you started advancing multiple frames just to check what happened. This is where the bots make movies on their own, where they think by themselves, where complicated bots become complicated. If you want to make a Lua bot that simulates your TASing (trying to find the fastest movie), you need to have a lot of ideas on how to solve the problems of - where the bot makes the savestates - how to give the inputs a score (for example a simple platformer would have a higher score if you are closer to the goal) - how to make the bot remember the best inputs - how to make the bot stop testing additional input (you don't want to test the same inputs, and you also don't want to brute force everything) Basically it's not too easy. tl;dr:
Warning: Might glitch to credits I will finish this ACE soon as possible (or will I?)
Joined: 10/2/2015
Posts: 91
I'm new to lua too! The best way as I've found was to just jump in and do some basic scripts. In order to write complicate code, you have to understand the basics first. AND look at other people's advanced scripts.
I didn't kill donkey, I saved it. Current projects: Misc Donkey hacks :) Past projects: Pacifist DKC1 DKC1 Entrance randomizer DKC2 Entrance randomizer DKDC (a troll hack of DKC1) DKC1 Enemy randomizer (among other things)