Question On Scripts And Autoexec.cfg

Status
Not open for further replies.

SeventhSentinel

In charge of way less than you might think
Administrator
Sonic Team Junior
Kart Krew™️
So, right down to business: My test script looks like this:
Code:
wait 300
echo "Done!"
And it is called "test.txt" (without the quotation marks of course).
When I go to type "exec test.txt" (no quotation marks) SRB2 just gives me, "Could not execute file test.txt". Also, when I make an autoexec.cfg that says the same thing, it too does not work. I'm a little confused as to why this isn't working. Some assistance would be greatly appreciated. Please and thanks.
 
Autoexec.cfg doesn't store scripts, it's a script itself that the game runs at startup. In order to do what you're intending, you have to make an alias, and because of what you're doing, it's kinda quirky how you'd have to do it. Let's start with a simple example:

alias test echo "Message"

Putting this into your autoexec.cfg will create a console command named "test", when when used will display "Message" as an echo. However, this only works for one console command per alias. In order to use multiple commands in an alias, you need to add quotation marks and semicolons, like so:

alias cheat "noclip; god;"

Putting this into your autoexec.cfg will create a console command named "cheat", which uses both the "noclip" and "god" commands, in that order. Note the semicolons and quotation marks, as they're important. You need quotation mark at the start and end of the alias, and a semicolon after every command, including the last. The problem here is that you can only use one set of quotations per line. In order to get around that, you have to get creative:

alias test2 echo "Done!"
alias test "wait 300; test2;"

This does what you want, creating a console command called "test" that waits 300 tics and then displays "Done!" as an echo. By creating a command in the first line and then using it in the second line, you can get around the restriction of only being able to use one set of quotation marks per line. Note that the order of the lines here is important. Putting the "test" alias first will produce an error because it'll try to use the command "test2" that you haven't defined yet.
 
SRB2 just gives me, "Could not execute file test.txt".

This means it can't find (or couldn't read, for some reason) the file to execute.

Are you sure you didn't make a typo somewhere? I think the filename might be case sensitive too.
 
Hello MetalHead7, welcome to our community.

I tried myself both ways and both worked.

I am not sure, but, I suspect your "test.txt" is not in srb2 folder. Please, make sure your "test.txt" is in srb2 folder, at the same folder where srb2 binary is located (if you are a Windows user, your srb2 binary is, for example, srb2win.exe).

When we use "exec", srb2 will try to find the script in srb2 folder. If you want something tidier, you can save all your scripts in a special folder: create one in srb2 folder and name it, say, "scripts". To execute the script: exec "scripts/test.txt". (Note: slashs require double quotes or it will not work).

Remember: autoexec.cfg is loaded on srb2 startup. Depending on you want to do, for example executing actions in game, I recommend you to execute manually the scripts in game or create an alias, like Mystic said.

More info: wiki.srb2.org/wiki/Script
 
Last edited:
Thanks guys, it all works now. Thanks for the warm welcome by the way. Keep on doing what you do. Have a nice day.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top