Page 332 of 396

Re: Ask a simple question, get a simple answer

Posted: Mon Oct 07, 2019 1:06 am
by Eleven Warrior
Do you need a tester for your mod?

Re: Ask a simple question, get a simple answer

Posted: Mon Oct 07, 2019 8:35 pm
by 7Soul
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'
Eleven Warrior wrote: Mon Oct 07, 2019 1:06 am Do you need a tester for your mod?
Me? Not yet

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 08, 2019 2:20 am
by Isaac
7Soul wrote: Mon Oct 07, 2019 8:35 pm 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'
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

Posted: Tue Oct 08, 2019 3:23 am
by 7Soul
Isaac wrote: Tue Oct 08, 2019 2:20 am
7Soul wrote: Mon Oct 07, 2019 8:35 pm 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'
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.
I'm a little lost maybe I explained my problem badly

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

Posted: Tue Oct 08, 2019 8:52 am
by Isaac
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?

Re: Ask a simple question, get a simple answer

Posted: Tue Oct 08, 2019 8:38 pm
by 7Soul
Isaac wrote: Tue Oct 08, 2019 8:52 am 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?
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

Posted: Wed Oct 09, 2019 10:56 am
by Isaac
7Soul wrote: Tue Oct 08, 2019 8:38 pm 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
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
The only other way that I am aware of, is to use the [volatile] Config object to hold your functions.

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

Posted: Wed Oct 09, 2019 11:00 am
by minmay
Isaac wrote: Wed Oct 09, 2019 10:56 am
7Soul wrote: Tue Oct 08, 2019 8:38 pm 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
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
this will crash when the player tries to save

Re: Ask a simple question, get a simple answer

Posted: Wed Oct 09, 2019 11:23 am
by Isaac
Yeah. :(
The ut variable would have to be local, inside of a 'do' block; along with the statements that use it.

Re: Ask a simple question, get a simple answer

Posted: Sun Oct 13, 2019 2:33 am
by Eleven Warrior
How do I change the ambient track in a level, like a plate connected to a function ty :)