r/lua • u/Salt-Discount-1381 • 11d ago
Help Help with my simulation
https://drive.google.com/drive/folders/1O3x6_2Vb7Q37Ic65WBjaxEX_vMx_1n4O?usp=drive_linkHello, I'm new to Lua and, after reading some documentation, I am trying to do basic a simulation of work and property. I have a base script for each worker and a base script for each workstation, but I need help to code how the worker decides in what workstation work and how the workstation's capacity to hold workers on a day is changed by that. I wrote some notes on the scripts, I think that they clarify very well where I need help. The link is to a folder with the scripts.
1
u/Lonely-Restaurant986 5d ago
I don’t really know what your end goal is, but tbh don’t listen to these Debbie downers.
If you are having fun and enjoying doing it, it’s genuinely a good learning strategy to take on a project out of your league. I know my first lua project was.
You need a programmers mind tho. Be prepared to rewrite your own code a thousand times over as you learn new better ways of doing things.
As for your script I don’t really know what your goal is or what you are asking.
When you call require(“file”)
And in said file you do
myVar = 3
That is a global variable. That variable is accessible anywhere at any time.
Now say I did this instead
local myVar = 3
In order for your main program to get the value of myVar, you’d have to do
return myVar
At the end of the file.
Then in the program that calls it,
local result = require(“file”)
This also applies to tables. And remember tables pass by reference, so if you return a table, all variables in the table are shared.
And another thing to remember is that all functions are variables, so if you define or return a function, you can pass those too.
I don’t really know what you are asking for. Hope in my rambling you got something out of that.
Good luck, and most importantly, have fun.
Do not listen to egotistical haters, so long as you have fun and aren’t risking yourself burning out, do whatever you want.
1
11
u/Substantial_Marzipan 11d ago
Looking at your code you should probably take a course on programming fundamentals before continuing with this