Ask a simple question, get a simple answer
- Eleven Warrior
- Posts: 745
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: Ask a simple question, get a simple answer
Do you need a tester for your mod?
Re: Ask a simple question, get a simple answer
Is there a way to include a lua file into another file? I'm trying to organize my 4k lines script, but I'm not having luck with 'loadfile' or 'require'
Me? Not yet
Re: Ask a simple question, get a simple answer
It depends on how you intend to use it.
Use: import "mod_assets/script/my_script.lua"
...in any of the startup scripts, to insert the contents of a file into that script when it's loaded.
There is a hoop to hop through for getting script_entity sources to load during the game.
You must first add a ScriptController component, and name it 'controller'; it must precede the script component in the definition. You must load the source for the Script component inside the ScriptController's onInit function.
Re: Ask a simple question, get a simple answer
I'm a little lost maybe I explained my problem badlyIsaac wrote: ↑Tue Oct 08, 2019 2:20 amIt depends on how you intend to use it.
Use: import "mod_assets/script/my_script.lua"
...in any of the startup scripts, to insert the contents of a file into that script when it's loaded.
There is a hoop to hop through for getting script_entity sources to load during the game.
You must first add a ScriptController component, and name it 'controller'; it must precede the script component in the definition. You must load the source for the Script component inside the ScriptController's onInit function.
I have a lua file called functions.lua, and in-game I have a script_entity (called "functions") that loads functions.lua, and I also import it in init.lua
What I was looking for was to divide functions.lua into smaller files, all loaded into the single script_entity, so all my functions.script.whatever() still work
Re: Ask a simple question, get a simple answer
Do you mean... having many single, or a few function containing scripts, and << somehow >> loading them all into one script_entity—while keeping the function files all separated?
If so, why—exactly/specifically?
If so, why—exactly/specifically?
Re: Ask a simple question, get a simple answer
I like keeping my functions organized when I do programming, maybe put my champion functions in one file, monster stuff in another, misc stuff in another, etc. I can't just put it in another script_entity because the I'd have to add "script_entity_name.script" in front of everything
Re: Ask a simple question, get a simple answer
You can define (at the top of every script) a shorter name for the script component—like "ut" for instance.
Code: Select all
ut = script_entity_name.script
Example:
Code: Select all
--objects.lua
--custom 'global'~ish functions
Config.Fn = {}
Config.Fn.chYell = function(champion) champion:playDamageSound() end
Config.Fn.chFormat = function(champion, text)
local text = text or ""
text = text:gsub("pro@", iff(champion:getSex()=='male','his', 'her'))
text = text:gsub("name@", champion:getName())
return text
end
Config.Fn.chRage = function(champion) champion:setConditionValue("rage", .1) end
Code: Select all
--script_entity_1
function stub()
if math.random(8) < 5 then
math.randomseed(Time.systemTime())
local champ = party.party:getChampion(math.random(4))
local eventStrings = {
"name@ stubbed pro@ toe!",
"name@ was bitten by fleas!",
"name@ has tripped!",
"name@ has something in pro@ eye!",
"name@ has itchy feet!",
}
Config.Fn.chYell(champ)
hudPrint(Config.Fn.chFormat(champ, eventStrings[math.random(#eventStrings)]))
Config.Fn.chRage(champ)
end
end
party.party:addConnector("onMove", self.go.id, "stub")
Re: Ask a simple question, get a simple answer
this will crash when the player tries to saveIsaac wrote: ↑Wed Oct 09, 2019 10:56 amYou can define (at the top of every script) a shorter name for the script component—like "ut" for instance.
Code: Select all
ut = script_entity_name.script
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Ask a simple question, get a simple answer
Yeah.
The ut variable would have to be local, inside of a 'do' block; along with the statements that use it.
The ut variable would have to be local, inside of a 'do' block; along with the statements that use it.
- Eleven Warrior
- Posts: 745
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: Ask a simple question, get a simple answer
How do I change the ambient track in a level, like a plate connected to a function ty