ID:2443303
 
Code:
mob/verb/CreateMacro(var/Letter as text)
var/action=input(usr,"Write the name of the command you want to macro, use a dash instead of SPACE","Macro") as text
winset(usr,"Macro[Letter]","parent=macro;name=[Letter];command=[action]")


Problem description: This command makes it so that a player from inside the game, can make a macro, and it works perfectly, the only problem is that when you exit the game and come back in, the macro didn't get saved, so what I want to know, is how can I save a macro with this code? Thank you in advance!

The way this is usually handled is by setting the key they're going to use for a specific action as a variable, then saving those settings to a BYOND key-specific savefile.

Although, I'm sure there are some brighter individuals than myself who've found better ways to handle it.

If you need help using savefiles, there are a buuuunch of savefile libraries on the Developers page.
In response to Spevacus
I have a Save System in my game already, but it doesn't save the macros, I was wondering if I had to use something like
F["Macros"]<<macros
or something like that in order to save them
Do you have "control freak" setting on?

If not, players can go to File, or right click the game's title bar, go to Client, and go to Macros and design their own macros there. They'll be saved on the user's computer and you can avoid saving through the server entirely.
In response to Spevacus
I thought I had it Off, because I have it Off in one code and On on another. I just turned it off to see if it works. Ok so I had control_freak set to 0 and it still doesn't save the macro, how I said before, the sistem works great, but it just doesn't save it. Yes, I know they could set a macro in Option and Messages, but I wanted to do it in a more aesthetic way.
Sure thing, completely understand.

The ways I've seen it done are to specify the command the new key is going to be applied to, whether by asking the user through a series of switch alerts or otherwise, then adding that to a specific variable, then saving and loading it there.

I would take the key as text, then...
NewMacro(key as text)
switch(input(src,"What command would you like to macro?","New Macro") in list("Attack","Block"))
if("Attack")
src.Attack_Key = "[key]"


You would know the way to save it, with...

F["AttackKey"]<<src.Attack_Key

Or something similar.

This would require you to have some sort of key handling with the new macros... But... Hey, it'll work.

Again, this feels like I'm needlessly hardcoding... Maybe there's someone else with a more elegant solution.
In response to Spevacus
Yeah, I saw that way to, but my game has hundreds of commands, I can put them all in a list and save them all. I will explain what I want to achieve, and this is something I got the idea from another game I saw once. I have button in the my interface called "Create a Macro", when the user clicks it, a rectangular window pops up, and it's full of button, a button for each key in the keyboard, each button has a command called "CreateMacro (and the key of the button you pressed)" and then the input pops out asking you to write which ever verb you have and with that the macro is made perfectly. If I knew how to put an image here I could show you.
You could upload that picture to imgur or something and paste the URL here if you'd like, though I think I get where you're coming from.

There's a library by Forum_account, the Handy Stuff library, that I believe would tackle your issue pretty easily, and lets you save the list created by it as well.

Here's a code snippet from it.

var
const
ALT = 1
CTRL = 2
SHIFT = 4
RELEASE = 8
REPEAT = 16

mob
proc
// The first argument is the key that was pressed. It's called
// "k" so it doesn't get confused with the mob's built-in key var.
// The second argument is a number that specifies the modifiers.
// See demo\demo.dm for an example of how to use macros.
macro(k, modifiers)

client
var
windows
list/macros
__macros_initialized = 0

New()
. = ..()
__init_macro_stuff()

verb
Macro(k as text, modifiers as num)
set hidden = 1
mob.macro(k, modifiers)

proc
add_macro(k, modifiers = 0)

if(!__macros_initialized)
__init_macro_stuff()

var/macro = __macro_name(k, modifiers)

for(var/m in macros)
winset(src, "[macro]", "parent=[m];name=[macro];command=Macro+\"[k]\"+[modifiers]")

remove_macro(k, modifiers = 0)
var/macro = __macro_name(k, modifiers)

for(var/m in macros)
winset(src, "[macro]", "parent=")

__macro_name(k, modifiers)
. = "[k]"
if(modifiers & ALT)
. = "Alt+[.]"
if(modifiers & CTRL)
. = "Ctrl+[.]"
if(modifiers & SHIFT)
. = "Shift+[.]"
if(modifiers & RELEASE)
. = "[.]+UP"
if(modifiers & REPEAT)
. = "[.]+REP"

__init_macro_stuff()
windows = winget(src, null, "windows")
macros = params2list(winget(src, windows, "macro"))
__macros_initialized = 1


Pretty handy. I guess that's why they call it Handy Stuff.
In response to Spevacus
Yeah, I see, looks kind of what I want, but I don't see where do you write the action done by the macro, but I'm seen that Macro verb, was a client verb and not a mob verb, so I'll try changing my code to a client verb and see if it changes anything.
Ok no, it still the same, the macro gets created, I can use it, but when I exit the game and come back in, it's not saved with my save proc, maybe if you could use the code I wrote, you could test it for yourself and see if it happens to you as well. Anyways, here's an image of what I the idea,
Ok, I got my problem solvded, a friend had a similar system and he helped me. Turned out that I had to make a macro of every key in the interface in orther to get properly saved.