I made a tram mod. It's a large industrial cargo tram measuring fifteen blocks wide. I tested it before adding the extra animation and it actual works, despite being three times as wide as a normal tram. Even the collision boundaries are accurate for it. The problem happens when I try to add in an extra animation. Trams have three basic animations: The tram itself, the gate, and the control arrows. I want to add a fourth one that I'm calling "grav lift". It's supposed to be like an energy assisted movement for the tram as it's supper heavy and (in imagination) is capable of carrying several tons of cargo and equipment. The animation itself is some pulsating blue energy under emitters on the bottom of the tram. I added in the .png, added a .frames file, added the animation part tag to the .vehicle file, and added all the proper lines of code to the .animation file. Everything works, the syntax is good, but... No animation. So digging around, I discovered that railtram.lua is what triggers the animations to play. I thought I could just do this to it: if self.railRider.onRailType and self.railRider.moving then animator.setAnimationState("rail", "on") and animator.setAnimationState("gravpulse", "pwrOn") else animator.setAnimationState("rail", "off") and animator.setAnimationState("gravepulse", "pwrOff") end Not only did it completely break my mod, but somehow it broke all the trams in the game. Digging through the log file, I saw that every tram was trying to reference the new animation and throwing an error because (obviously) they didn't have the assets for the new animation. Strangely, my mod was throwing the same error. So how do I add the extra animation? It needs to be a separate animation, as that's the only way that I know of to keep the energy effect at fulbright without affecting the whole tram. Did I just not edit the .lua correctly? And how do I stop changes to the .lua from affecting all the other trams? Can I just somehow write it into the .animation file so the .lua triggers it when it triggers the rail animation? I feel like I have no idea what I'm doing, so any help would be appreciated. UPDATE: I figured it out. My first mistake was trying to alter the vanilla lua. My second mistake was not giving my unusually large frames their own unique names. The fix was to not try getting the lua to activate it as a separate animation, but instead label everything in the animation file so that "rail on/off" was associated with the gravpulse animation states as well as the tram.
I think you'll probably need both a .animation and a custom .lua based off the current tram lua. Replacing the vanilla Lua file isn't really a great idea anyways, since Lua files have to be replaced and not patched; if anyone else were to make a similar mod patching the lua, yours would be incompatible with theirs unless their overloading file is exactly the same as yours.
A custom .lua? So would I just rewrite the bit from the tram lua into a custom lua and reference it in the vehicle file?
Ok, so I tried making a custom .lua to handle the extra animation, and added it to the list of scripts to run in the .vehicle file. gravpulse.lua looks like: require "/vehicles/railtram/railtram.lua" function update(dt) if self.railRider.onRailType and self.railRider.moving then animator.setAnimationState("gravpulse", "pwrOn") else animator.setAnimationState("gravpulse", "pwrOff") end end and the part in cargoTram.vehicle looks like: "scripts" : { "/vehicles/railtram/railtram.lua" : "/vehicles/railtram/gravpulse.lua" }, I got the same result. Even the custom .lua is breaking the other trams.
Did you change the original lua back to the default state it comes in, and make sure every vanilla tram is still pointing to the regular lua?
I figured it out. I chucked the .lua out entirely as I discovered that it's used by all trams and what I was trying to do had nothing to do with it. The problem was coming from me trying to use default.frames as the frames file for the tram itself. I blame the Industrial Tram mod that I was using as an example. For that mod, doing that would be fine, but my mod used an entirely different frame size, and so everything that tried pulling from default.frames was throwing image size mismatch errors. In the end, I made my own .frame file to handle my mod, wrote in the extra animation to use the same "rail: on, off" part states that main trams use so the default lua triggers it when it should without any changes, and as an extra precaution gave every single frame associated with the "rail" part state it's own unique name. Lesson of the day: Don't touch the vanila lua files.