The dev loop: edit, reload, read the console
Here is a secret that makes the rest of FiveM development feel easy: almost every change you make follows the same short loop. You edit a file, you reload the resource, and you read the console to see what happened. That is the whole rhythm. Once it feels automatic, you stop fearing changes and start making a lot of them fast. This lesson teaches you that loop and the three commands that drive it.
What the dev loop is
A dev loop is the short cycle you repeat every single time you change your code. It has three beats, and they always happen in the same order:
- Edit a file and save it.
- Reload the resource so the server picks up your new code.
- Read the console to see what your code actually did.
That is it. Edit, reload, read. You will run this loop thousands of times, so it is worth slowing down once to understand each beat instead of copying commands and hoping.
The reason the loop exists is simple: saving a file does not change a running server. The server already loaded your old code into memory when it started. Your saved edit is sitting on disk, but the server is still running the version it loaded earlier. The reload step is how you tell the server, throw away the old version and load my new one. The read step is how you find out whether that worked.
Vocabulary
- ensure
- A console command that starts a resource, or restarts it if it is already running. The safe default.
- restart
- A console command that reloads a resource that is already running. This is what you type after most edits.
- refresh
- A console command that makes the server re-scan its resources folder for new resources or changed manifests.
- console
- A text window where you type commands to the server and where the server prints messages back. Your two-way line to the running server.
- F8
- A key you press in the game to open the client console, where prints from client code appear.
Why it matters
When you change a webpage, you reload the browser tab and the change is there. FiveM works the same way, except the thing you reload is one resource, not the whole game.
This is the part that trips up beginners coming from no background at all. They assume that to test a change they have to close FiveM, shut down the server, start everything back up, and reconnect. That takes minutes, and it makes you afraid to experiment. You are not going to do that. The server stays running the entire time you work. When you change one resource, you reload only that one resource, and it happens in well under a second.
So the real speed of FiveM development is not how fast you type Lua. It is how tight you can make this loop. Edit, reload, read, all in a couple of seconds, over and over. The faster the loop, the faster you learn, because you see the result of every change almost instantly.
The three commands
You drive the loop with three commands. You type them into the txAdmin Live Console (the text box at the bottom of the txAdmin web panel where you send commands to the server) or into the raw server console window if you run the server directly. Both are the same console. Here is what each command does and when you reach for it.
ensure
ensure starts a resource. If the resource is stopped, it starts it. If the resource is already running, it restarts it instead. That two-in-one behavior is why ensure is the safe default: it does the right thing no matter what state the resource is in.
ensure qu_helloThis is also the line you put in server.cfg so the resource comes up every time the server boots. Use ensure the first time you bring a resource up in a session, when you are not sure if it is running, or any time you just want it on.
restart
restart reloads a resource that is already running. It stops the resource, then starts it again, which loads your latest saved code.
restart qu_helloThis is your everyday command. After you edit a file and save, you type restart qu_hello and your new code is live. If you try to restart a resource that is not running yet, nothing useful happens, because there is nothing to reload. So ensure first to bring it up, then restart after each edit.
refresh
refresh does not start or reload any specific resource. It tells the server to re-scan its resources folder and notice things that are new: a brand new resource folder you just created, or a changed fxmanifest.lua (the file that lists what a resource contains).
refreshYou only need refresh at two moments: right after you create a brand new resource folder, and after you change a manifest. The server learns about new resources only when you ask it to look. For day-to-day edits inside a resource it already knows about, you skip refresh entirely and just restart.
A quick way to remember the split: restart reloads code the server already knows about. refresh makes the server discover resources it does not know about yet. New folder, run refresh once, then ensure. Changed code in an existing resource, just restart.
Do a full loop
Let us run the loop once, start to finish, on the qu_hello resource. You will add one print line, reload, and watch it appear. A print is a line of code that writes a message to the console, so you can see that your code ran.
Edit server.lua
Open server.lua inside your qu_hello resource folder and add this line near the top:
print('[qu_hello] dev loop works')Save the file
Save the file. In most editors that is Ctrl+S. Saving alone changes nothing on the running server yet. The edit is on disk, but the server is still running the old code. That is exactly why the next step exists.
Reload the resource
In the txAdmin Live Console, type this and press Enter:
restart qu_helloRead the console
Watch the console output right after the restart. Among the server's own status lines you will see the line you added.
The first line is the server telling you it brought the resource up. The second line is your own print, and seeing it is the proof that closes the loop: your new code is live and it ran. If you only saw the first line and not your printed line, the server did not reach your code, and you would go read the rest of the console for an error. That is the loop. Edit, reload, read.
Where output appears
Beginners lose hours here, so read this twice. Your print lines do not all go to the same place. Where a print shows up depends on which side of the resource the code runs on.
So when you add a print and reload but see nothing, do not assume your code is broken. Ask first: is this server code or client code? Then look in the matching console. Half the time the print was there all along, just in the other window.
Common beginner mistakes
These three account for most of the "my code isn't working" moments at the start. None of them are real code bugs.
| Symptom | Fix |
|---|---|
I changed the code but nothing changed. | You saved the file but did not reload the resource. The server is still running the old code. Run restart qu_hello and watch the console again. |
Resource qu_hello does not exist | You just created the folder and the server has not scanned it yet. Run refresh once so the server discovers it, then ensure qu_hello to start it. |
I added a print to client code but it never shows in the server console. | Client prints go to the client console, not the server console. Press F8 in the game to open it and look there instead. |
You edited server.lua. Which command makes the change take effect?
restart. You saved the file, but the server is still running the old code in memory. restart qu_hello stops and re-starts that one resource, which loads your latest saved code. You only need refresh first if the resource is brand new and the server has never scanned its folder.
Try it yourself
What you can do now
- Run the full dev loop on purpose: edit a file, save it, reload the resource, read the console.
- Choose the right command for the moment: ensure to bring a resource up in any state, restart to reload changed code, refresh to make the server discover a brand new folder.
- Reload one resource in under a second instead of relaunching the whole game or server.
- Look in the correct console: server prints in the server console, client prints in F8.
- Diagnose the three classic no-change moments without assuming your code is broken.
You can now create, configure, and reload a resource, so next you will make it actually DO things with events, commands, and exports. The next module is "Making things happen."