13 Jan 2024 |
plan9fromtauceti | is that the leftmost column of your text editor | 19:16:05 |
clavernever | Actually, adding "doneonce" checkers to onInit is redundant I think | 19:16:24 |
clavernever | Haven't added them yet, as I was delaying actual game testing and using dummy values with the lua console instead | 19:17:05 |
clavernever | I'll put all the function creators and data structures (internal attribute tables for the script, etc) there to make sure they only run once when the script is created and don't get called again ever | 19:18:04 |
plan9fromtauceti | i think the syntax is wrong here, presuming that
oninit
dofivetimepersecond = 0
dooncepersecond = 0
is the definition of the oninit function the correct syntax is
local function oninit()
local dofivetimespersecond = 0
local dooncepersecond = 0
end | 19:18:32 |
plan9fromtauceti | * i think the syntax is wrong here, presuming that
oninit
dofivetimepersecond = 0
dooncepersecond = 0
is the definition of the oninit function, the correct syntax is
local function oninit()
local dofivetimespersecond = 0
local dooncepersecond = 0
end | 19:18:42 |
clavernever | Unless the script gets "created" every time a player loads if so, I'll use onLoad with a doneonce checker | 19:19:03 |
clavernever | ye many thanks, seeing an actual example helps a lot | 19:19:38 |
clavernever | must all things be started with local to make them script exclusive?
In other words, if I don't add said local, will that make them global to the entire lua environment ingame? | 19:20:37 |
clavernever | cause that wouldn't be what I intended | 19:21:02 |
clavernever | (if any of my questions seem dumb or obvious, do note I only program mods as a hobby and haven't done any official courses, I learn what I need on the go to do what I want and that's about it as far as academics goes) | 19:22:42 |
zackhasacat | That's how I am | 19:24:22 |
plan9fromtauceti | no idea if its global to the entire lua environment, but its at least global to the file its contained in, but even then i'd just recommend defining any variables you want to access anywhere in the file in the top level scope | 19:24:36 |
plan9fromtauceti | like instead of having
local function foo()
myGlobalVar = 5
end
foo()
print(myGlobalVar)
id just do
local myTopLevelScopeVar = 3
local function foo()
myTopLevelScopeVar = 5
end
foo()
print(myTopLevelScopeVar) | 19:26:32 |
plan9fromtauceti | * like instead of having
local function foo()
myGlobalVar = 5
end
foo()
print(myGlobalVar)
id just do
local myTopLevelScopeVar = 3
local function foo()
myTopLevelScopeVar = 5
end
foo()
print(myTopLevelScopeVar) | 19:26:46 |
plan9fromtauceti | * like instead of having:
local function foo()
myGlobalVar = 5
end
foo()
print(myGlobalVar)
id just do
local myTopLevelScopeVar = 3
local function foo()
myTopLevelScopeVar = 5
end
foo()
print(myTopLevelScopeVar) | 19:27:02 |
clavernever | hmmmmmmmmmmmmm I'm in the habit of letting global be default and using local explicitly to denote stuff that is not intended to to be accessed anywhere else, but I guess I'll add local to everything and simply name temp variables explicitly to remind myself of it
Seems like a safer way to do things, since I don't want to have any chances of my code randomly breaking when other mods are present (or breaking the other mods, or both) | 19:27:47 |
plan9fromtauceti | seems like you can access any globally scope stuff throughout the entire runtime | 19:31:29 |
plan9fromtauceti | myFile.lua could have:
GlobalVariable = 5
and myOtherFile.lua could access it (and redefine it) using:
_G.GlobalVariable = "Ha ha now its a string" | 19:32:15 |
clavernever | yeah seems.. cool for mod integration (say you could have certain globals defined explicitly to let other mods, yours or otherwise, interface with your mod) but also vulnerable to causing problems if you make multiple scripts from a single mod (say a script that gets attached to all NPCs may overwrite itself from its other instances) or cause conflicts if used carelessly (I would NOT make a "doonce" variable global, ever) | 19:37:15 |
plan9fromtauceti | openMW already has stuff to deal with communicating between scripts and mods that are cleaner than messing with _G but im getting ahead of myself and its not really relevant | 19:39:13 |
clavernever | Guess it would make sense to have it that way.. the global approach seems easier but prone to errors, while using dedicated methods seems safer but a bit more involved than just calling globals | 19:43:52 |
clavernever | anyways, on to making the handlers work and testing in-game | 19:44:23 |
| .yannik changed their display name from Yannik to .yannik. | 19:59:37 |
| plan9fromtauceti changed their profile picture. | 20:25:52 |
14 Jan 2024 |
| DarthGandalfchanged room power levels. | 16:09:32 |
| @lenny:flipdot.org left the room. | 17:18:25 |
16 Jan 2024 |
| @y3l0b3b5z2u=:matrix.org left the room. | 13:56:44 |
3 Apr 2024 |
| @atrayonis:matrix.org left the room. | 18:29:05 |
23 Apr 2024 |
| @lumbo7332:matrix.org left the room. | 06:47:54 |