Small Question/Problem Concerning Presets

I hope this is the correct discussion. I feel a little silly because this looks incredibly easy to make, but somehow I’m just not writing this correctly. Seeing as I can’t include .txt files while uploading an addon to the Workshop, I’m trying to turn these little scripts into a .lua file. Hopefully I have this right so far, I’ve never done scripting before. Basically I’m just trying to include some presets for the Colour Tool to go along with some TF2 ragdolls, but I’m having a tad of trouble with the format no matter how much I edit it. At the moment this is what I have:


presets.Add( "color", "A Color Similar To Slate", {
	colour_mode = 5
	colour_r = 47
	colour_g = 79
	colour_b = 79
	colour_a = 255
})

I did take a look at this page and made small changes here and there with each trial such as adding quotes, placing commas, having it all on one line, tabbing instead of an equal sign; random things like that, but no such luck. With the format I currently have, this is the error I get:

[ERROR] addons\colourable tf2 mercenaries\lua\autorun f2paintcolours.lua:3: ‘}’ expected (to close ‘{’ at line 1) near ‘colour_r’
1. unknown - addons\colourable tf2 mercenaries\lua\autorun f2paintcolours.lua:0

I’m assuming it’s asking me to place a bracket before or after the red colour line, but then that cuts off the rest of the code. I want to add more colours as well, but I’m trying to get at least one working properly first before I try adding more. Also, in case it’s a concern, there’s spaces in “colourable tf2 mercenaries” instead of underscores, whether it matters or not in this case, because at the moment I have the files mounted manually for quicker editing rather than continuing to update the Workshop addon. Any kind of help would be greatly appreciated and thank you very much for your time.

You are missing commas.
colour_mode = 5,
colour_r = 47,
etc

Just commas? Huh. I tried doing that before, but problems appeared as well. Just to double-check, here’s the new setup:


presets.Add( "color", "A Color Similar To Slate", {
	colour_mode = 5,
	colour_r = 47,
	colour_g = 79,
	colour_b = 79,
	colour_a = 255
})

And the error I’m receiving this time is this:

*[ERROR] addons/colorable tf2 mercenaries/lua/autorun/tf2paintcolours.lua:1: attempt to index global ‘presets’ (a nil value)

  1. unknown - addons/colorable tf2 mercenaries/lua/autorun/tf2paintcolours.lua:1*

I think it tried giving me particle errors as well, but I can’t say for certain… My apologies if this starts to become complicated.

If you would look at the wiki, you would realize that presets is a clientside only library.

I’m aware, or at least I think I am. I’m not sure how or why that error happened after only placing commas into the file. My only intent is to create presets for the Colour Tool in the addon. Unfortunately it won’t accept the .txt files I have done, so I’m trying to convert them. Perhaps it should be a different folder path rather than “lua/autorun/”? Or… were you saying that this won’t work either way? If that’s the case I apologize for the waste of time, but thank you for the help.

You should either put it into lua/autorun/client/ or do “if SERVER then return end” at the top of the file.

I am not sure, but you might need to AddCSLuaFile() the file from server side so it is sent to clients. Some people say it is done automatically for autorun files, but I am not sure.

Adding the client folder seems to have worked, or at least it stopped any errors. The only thing it complains about now is “TODO: savepresets” which I’m not entirely sure what to do with… Ahh, my apologies if I didn’t mention it before, but I don’t plan to have this for multiplayer use, or at least not at the moment. I want to see if it’s possible to make it work for singleplayer first. It’s a small thing, so it’s alright if we can’t figure it out. I appreciate the help, though.

That means that presets are not saving over restarts. It’s a bug with with GMod.

Ahhh, I see… I suppose that’s that, then. Thank you once again for your help.

That shouldn’t matter though since you are adding presets every time you start a server.