Commish's Dev Blog #7: What's a LUA script?

by Cameron Irvine

The SFL has been around for 22 seasons, or 11 years. When I started this league, I didn't know much about anything related to video games. I didn't really even start playing video games until I was a teenager. Fast forward to 2024, I still don't know much about video games, but I know much more than the average person when it comes to football games.

When a controller is in a person's hand, they control the outcome - especially when facing another user. The obvious advantage of that for the user is the control - you have more to do with the outcome of the game. The disadvantage of that, however, is the person's flaw to do anything to win. 

I started the SFL because I believe that an AI programmed to play the sport I love would play it more responsibly than a human ever could, unless that human's number one goal was to create a realistic product with their play - and I still believe that to this day. I see it every day in the SFL and sadly I am the one that is left to protect that mission - it is by far the worst part of my job. 

With all that being said, an important component I've come to learn when it comes to simulations are LUA scripts. Well, what the heck is that? LUA scripts essentially are the AI's brain, how the AI thinks, in every situation of the simulation. Every component of a football game is a game following a script but the differences lie in what plays it has to select from, what attributes your players possess and some random dice rolls thrown in there to vary up decision-making for good measure. Yep, that's how it works. Let's give an example:

if (GETYARDSTOENDZONE() > COMMON_GiveUpDistance) then  

                    if (GETTIMEREMAININGHALF() < 35) then




What does this line of code tell us? Well, first we have to understand what section of the brain this code is coming from. In this example, this line of code comes from second quarter logic, with under 35 seconds to go. Let's start from the top:

  • if (GETYARDSTOENDZONE() > COMMON_GiveUpDistance). The game is calculating in this moment how far away the offense is from the end zone. Then, it's looking up the give up distance - essentially - are we too far away to get aggressive and try to score before the end of the half? There is a COMMON_GiveUpDistance that is universal to every team in the game - it's not something that each team can have all to their own. Let's say that the distance is 70 yards away from the end zone. That means, if we're on our own 28 yard line and there's less than 35 seconds left to go in the half, the AI is going to choose to not push the ball down the field. 

You've seen this happen in SFL games from the beginning, asking out loud in the chat, "Why aren't we trying to go score!?" If you were in control, maybe you would - but you're not - because this is a controllerless league. That's what it is. Understanding what you're looking at. Knowledge can help everyone better understand what's happening.

Console LUA scripts are not accessible to the public and in PC games, if you're fortunate enough to be able to identify their location in the game's DNA, LUA scripts cannot remove or add any code without severely damaging the brain. Think about changing LUA scripts as brain surgery - one wrong move and the brain could be damaged or shut down all together.

In APF, there was a LUA script that stated if you're down by more than 3 and there is less than five minutes to go, onside kick. It drove everyone crazy. In 4K23, that LUA script is different and we see kickoffs deep later into games all the time. Every game has a different AI brain and what I've learned over 11 years is it doesn't matter what game you choose, there will always be holes in logic that cannot account for every single second, every single situation, every single moment of football. Football is a complex sport and if developers truly cared about the art of simulation AI, they could spend years writing code, second by second of each potential outcome of football.

  • Team A is down 17-10 on their own 46 with 1 timeout and 38 seconds to go - what do they do?
  • Team A is up 24-21 on their own 2 yard line with 5:30 left in the 4th quarter and Team B has all three timeouts and it's 2nd down & 8 - what does Team B do?
  • Team A and Team B are tied and Team A is on the fringe of field goal range, just completed a pass to the opponents 32 yard line, it's 4th and 2 and there's 21 seconds left. What does Team A or Team B do?

4K23 is the SFL's game. It has it's own brain and it's brain has it's own flaws. There's nothing we can do about it and the sooner everyone accepts that, the sooner they'll be able to find peace with what they can control, and what they can't and enjoy the entertainment for what it is. Mental health is important, and knowledge is power. My goal, through Season 23 is to help every player and team in this league better understand what they're watching so that we can all be just a little more mentally strong in the moments of defeat.

In this blog, I broke down one situation, in one moment in time. Not adding in what the score is, what the down is, how many timeouts you have - all of those sections of the brain factor into every decision that the viewer watches play out in real time. 

To some, this topic doesn't mean much. We've got All-Stars, Hall-of-Fame, an off-season schedule and so much more to finalize as we prepare for Season 23 and the SFL Convention in Houston in July. But on this day, I felt like this was important enough to touch on because I don't talk about it enough and it should be talked about more. 

To everyone on this Mother's Day, I hope you are celebrated and are at peace with how life is going. Everyone needs a little peace. 

“Grant me the serenity to accept the things I cannot change, the courage to change the things I can, and the wisdom to know the difference.”

Reinhold Niebuhr, American Theologian