Jump to content

How do I include another lua file inside a prefab script?


Recommended Posts

Hello, I am trying to access another Lua file inside a prefabs script.

I have my own custom character, has their own voice lines, I want to add custom voice lines.

I can not find how to pull from the speech_<characterName> file that was loaded so I decided to try and make my own

So I set it up

-- scripts/Custom_Speech.lua
return {
    TEST_SPEECH = "This is a test"
}

in my prefab I just need to access TEST_SPEECH so I try

-- scripts/prefabs/MyCharacter.lua
local custom_speech = dofile("../Custom_Speech.lua") -- tried without ./ and ../ didn't work

-- Initial setup code

local onAssosiatedAction
	-- For scenario sake whenever this assosiated action whether that be equip, unequip etc triggers do this
	inst.components.talker:Say(custom_speech.TEST_SPEECH)
end

-- The rest of the code

I've also tried using `require` instead of `dofile` but they both just seem to choke and I can't get it to do what I want and I've been at this for over 5 hours and feel like I'm going around in circles.

 

I just want to pull my quotes from a seperate file instead of hard coding them in the script.

Edited by Lyraedan
Link to comment
Share on other sites

Quotes from your mod should all be accessible with the STRINGS file just from anywhere just like TUNING is, because of this line in your modmain :

STRINGS.CHARACTERS.MY_CHARACTER = require "speech_mycharacter"

so if you wanted to take the generic battlecry quote, it would be STRINGS.CHARACTERS.MY_CHARACTER.BATTLECRY.GENERIC where MY_CHARACTER is whatever you put in for that in the code above

Link to comment
Share on other sites

8 hours ago, Merkyrrie said:

Quotes from your mod should all be accessible with the STRINGS file just from anywhere just like TUNING is, because of this line in your modmain :

STRINGS.CHARACTERS.MY_CHARACTER = require "speech_mycharacter"

so if you wanted to take the generic battlecry quote, it would be STRINGS.CHARACTERS.MY_CHARACTER.BATTLECRY.GENERIC where MY_CHARACTER is whatever you put in for that in the code above

This seems to have at least allowed me to place my custom voice lines in the speech file, for that I am thankful.

Odd because last time I tried to access STRINGS it told me "STRINGS" was undeclared but now it works.

Thank you :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...