!bZkoSqWsCTysAjmRaC:matrix.org

OpenMW Lua

1568 Members
https://openmw.org/ || Rules: https://rentry.co/omw_rules || Other rooms related to OpenMW: #openmw-space:matrix.org5 Servers

Load older messages


SenderMessageTime
13 Jan 2024
@_discord_325534431756550144:t2bot.ioplan9fromtauceti is that the leftmost column of your text editor 19:16:05
@_discord_384870211381100544:t2bot.ioclavernever Actually, adding "doneonce" checkers to onInit is redundant I think 19:16:24
@_discord_384870211381100544:t2bot.ioclavernever Haven't added them yet, as I was delaying actual game testing and using dummy values with the lua console instead 19:17:05
@_discord_384870211381100544:t2bot.ioclavernever 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
@_discord_325534431756550144:t2bot.ioplan9fromtauceti 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
@_discord_325534431756550144:t2bot.ioplan9fromtauceti * 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
@_discord_384870211381100544:t2bot.ioclavernever Unless the script gets "created" every time a player loads
if so, I'll use onLoad with a doneonce checker
19:19:03
@_discord_384870211381100544:t2bot.ioclavernever ye many thanks, seeing an actual example helps a lot 19:19:38
@_discord_384870211381100544:t2bot.ioclavernever 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
@_discord_384870211381100544:t2bot.ioclavernever cause that wouldn't be what I intended 19:21:02
@_discord_384870211381100544:t2bot.ioclavernever (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
@_discord_127678330722844672:t2bot.iozackhasacat That's how I am 19:24:22
@_discord_325534431756550144:t2bot.ioplan9fromtauceti 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
@_discord_325534431756550144:t2bot.ioplan9fromtauceti 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
@_discord_325534431756550144:t2bot.ioplan9fromtauceti * 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
@_discord_325534431756550144:t2bot.ioplan9fromtauceti * 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
@_discord_384870211381100544:t2bot.ioclavernever 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
@_discord_325534431756550144:t2bot.ioplan9fromtauceti seems like you can access any globally scope stuff throughout the entire runtime 19:31:29
@_discord_325534431756550144:t2bot.ioplan9fromtauceti 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
@_discord_384870211381100544:t2bot.ioclavernever 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
@_discord_325534431756550144:t2bot.ioplan9fromtauceti 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
@_discord_384870211381100544:t2bot.ioclavernever 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
@_discord_384870211381100544:t2bot.ioclavernever anyways, on to making the handlers work and testing in-game 19:44:23
@_discord_98862751723577344:t2bot.io.yannik changed their display name from Yannik to .yannik.19:59:37
@_discord_325534431756550144:t2bot.ioplan9fromtauceti changed their profile picture.20:25:52
14 Jan 2024
@darthgandalf:matrix.orgDarthGandalfchanged room power levels.16:09:32
@lenny:flipdot.orgLenny. left the room.17:18:25
16 Jan 2024
@y3l0b3b5z2u=:matrix.orgoxo left the room.13:56:44
3 Apr 2024
@atrayonis:matrix.orgAtrayonis left the room.18:29:05
23 Apr 2024
@lumbo7332:matrix.orgPope_Rigby left the room.06:47:54

There are no newer messages yet.


Back to Room ListRoom Version: 6